You are on page 1of 33

17-05-2021

GIT

PAPARAO.C

WHAT IS GIT?

 Started in 2005
 Created by Linus Torvald to aid in Linux kernel development
 Distributed version control
 Users keep entire code and history on their location machines
 Users can make any changes without internet access
 (Except pushing and pulling changes from a remote server)
 Git is optimized for:
• Distributed development
• Large file counts
• Complex merges
• Making trial branches
• Being very fast
• Being robust

OTHER SCM

1
17-05-2021

WHAT IS VERSION CONTROL?

 A system that keeps records of your changes


 Allows for collaborative development
 Allows you to know who made what changes and when
 Allows you to revert any changes and go back to a previous state

2
17-05-2021

3
17-05-2021

INSTALL GIT

 Linux (Debian)
 Command: sudo apt-get install git!
 Linux (Fedora)
 - Command: sudo yum install git!
 Mac
 - http://git-scm.com/download/mac
 Windows
 - http://git-scm.com/download/win

10

CREATE GITHUB ACCOUNT

 www.github.com
 Free for public repositories

11

HOW DOES GIT WORK?

 Snapshots
 Commit
 Repositories
 Branches
 Merging

12

4
17-05-2021

KEY CONCEPTS: SNAPSHOTS

 The way git keeps track of your code history


 Essentially records what all your files look like at a given point in time
 You decide when to take a snapshot, and of what files
 Have the ability to go back to visit any snapshot
 Your snapshots from later on will stay around, too

13

KEY CONCEPTS: COMMIT

 The act of creating a snapshot


 Can be a noun or verb
 “I commited code”
 “I just made a new commit”
 Essentially, a project is made up of a bunch of commits

14

KEY CONCEPTS: COMMIT

 Commits contain three pieces of information:


1. Information about how the files changed from previously
2. A reference to the commit that came before it
 Called the “parent commit”
3. A hash code name
 Will look something like:
fb2d2ec5069fc6776c80b3ad6b7cbde3cade4e

15

5
17-05-2021

16

17

KEY CONCEPTS: REPOSITORIES

 Often shortened to ‘repo’


 A collection of all the files and the history of those files
 Consists of all your commits
 Place where all your hard work is stored
 Can live on a local machine or on a remote server (GitHub!)
 The act of copying a repository from a remote server is called cloning
 Cloning from a remote server allows teams to work together

18

6
17-05-2021

KEY CONCEPTS: REPOSITORIES

 The process of downloading commits that don’t exist on your machine from a remote repository is called pulling
changes
 The process of adding your local changes to the remote repository is called pushing changes

19

THE GIT REPO

 A “working tree” has a “.git” dir at the top level


 The .git dir contains:
 config – Configuration file (.ini style)
 objects/* – The object repository
 refs/heads/* – branches (like “master”)
 refs/tags/* - tags
 logs/* - logs
 refs/remotes/* - tracking others
 index – the “index cache” (described shortly)
 HEAD – points to one of the branches (the
“current branch”, where commits go)

20

21

7
17-05-2021

GIT SPEAKS AND LISTENS

 Many protocols to transfer between repos


rsync, http, https, git, ssh, local files
 In the core, git also has:
 import/export with CVS, SVN

22

23

24

8
17-05-2021

25

26

27

9
17-05-2021

28

29

30

10
17-05-2021

31

32

33

11
17-05-2021

34

35

36

12
17-05-2021

37

38

39

13
17-05-2021

40

41

42

14
17-05-2021

43

44

45

15
17-05-2021

46

47

48

16
17-05-2021

49

50

51

17
17-05-2021

52

53

54

18
17-05-2021

55

56

57

19
17-05-2021

58

KEY CONCEPTS: BRANCHES

 All commits in git live on some branch


 But there can be many, many branches
 The main branch in a project is called the master branch

59

60

20
17-05-2021

WHAT IS MASTER?

 The main branch in your project

61

BRANCHING OFF OF THE MASTER BRANCH

 The start of a branch points to a specific commit


 When you want to make any changes to your project you make a new branch based on a commit

62

63

21
17-05-2021

64

65

66

22
17-05-2021

67

68

69

23
17-05-2021

70

71

72

24
17-05-2021

KEY CONCEPTS: MERGING

 Once you’re done with your feature, you merge it back into master

73

74

75

25
17-05-2021

76

77

78

26
17-05-2021

79

80

81

27
17-05-2021

82

83

84

28
17-05-2021

HOW DO YOU MAKE A COMMIT


ANYWAY?

 There are a lot of ‘states’ and ‘places’ a file can be


 Local on your computer: the ‘working directory’
 When a file is ready to be put in a commit you add it onto the ‘index’ or ‘staging’
 Staging is the new preferred term – but you can see both ‘index’ and ‘staging’ being used
 The process:
 Make some changes to a file
 Use the ‘git add’ command to put the file onto the staging environment
 Use the ‘git commit’ command to create a new commit’

85

MERGE COMMITS

 Retains all of the


commits in your branch
and interleaves them
with commits on the
base branch

86

MERGE SQUASH

 Retains the changes


but omits the
individual commits
from history
 Merge squash
merges a tree (a
sequence of
commits) into a
single commit. That
is, it squashes all
changes made
in n commits into a
single commit.

87

29
17-05-2021

REBASE

 This moves the entire feature


branch to begin on the tip of the
master branch, effectively
incorporating all of the new
commits in master
 Rebasing is re-basing, that is,
choosing a new base (parent
commit) for a tree. Maybe the
mercurial term for this is more
clear: they call it transplant because
it's just that: picking a new ground
(parent commit, root) for a tree.
 When doing an interactive rebase,
you're given the option to either
squash, pick, edit or skip the
commits you are going to rebase.

88

WHAT IS GITHUB?

 www.github.com
 Largest web-based git repository hosting service
 Aka, hosts ‘remote repositories’ • Allows for code collaboration with anyone online
 Adds extra functionality on top of git
 UI, documentation, bug tracking, feature requests, pull requests, and more!
 Founded in 2008
 Also has an Enterprise edition for businesses

89

GIT COMMANDS

90

30
17-05-2021

BASIC COMMANDS

 git init
 git clone
 git log
 git diff
 git status
 git add
 git commit

91

GIT INIT

 Creates a new git repository


 Can be used to convert an existing, unversioned project to a git repository or initialize a new empty
repository

92

GIT CLONE

 Copies an existing git repository

93

31
17-05-2021

GIT LOG

 Shows the commit logs

94

GIT ADD

 Adds changes

95

GIT COMMIT

 Creates a commit out of the changes that had been added

96

32
17-05-2021

GIT DIFF

 Displays the change that was introduced


 Useful flag:
 --cached:
 Displays the change that was added using “git add”

97

GIT STATUS

 Displays the file names that has been modified, added and untracked

98

GIT CHEAT SHEET

99

33

You might also like