VCS concept
Version Control with Git. DevTestOps training.
Standalone work. Level 1 - beginner
Team work. Level 2 – network share
Standalone/Team work. Level 3 - cloud
VCS goals
1 BACKUP AND RESTORE
2 SYNCHRONIZATION
3 UNDO
4 TRACK CHANGES AND OWNERSHIP
5 SANDBOXING
6 BRANCHING
5
Version control
types
Version Control with Git. DevTestOps training.
VCS types
LOCK-MODIFY-UNLOCK COMBINED COPY-MODIFY-MERGE
SCCS, VAULT CVS, Git, Mercurial,
SVN, Perforce, TFS
GNU Bazaar
7
Lock-modify-unlock strategy
Sword and spear
Wall of shields
Locked by Alice
song.txt
Sword and spear
Wall of shields
ALICE BOB
8
Lock-modify-unlock strategy
Sword and spear
Wall of shields
Bob updates his local copy
song.txt
Sword and spear Sword and spear
Wall of shields Wall of shields
ALICE BOB
9
Lock-modify-unlock strategy
Sword and spear
Wall of shields
Standing strong
On this their chosen battle field
Locked by Bob
song.txt
Sword and spear Sword and spear
Wall of shields Wall of shields
Standing strong
On this their chosen battle field
ALICE BOB
10
Lock-modify-unlock strategy
Sword and spear
Wall of shields
Standing strong
On this their chosen battle field
Unlocked by Bob
song.txt
Sword and spear Sword and spear
Wall of shields Wall of shields
Standing strong
On this their chosen battle field
ALICE BOB
11
Copy-modify-merge strategy
Sword and spear
Wall of shields
Alice push changes
song.txt
Sword and spear Standing strong
Wall of shields On this their chosen battle field
ALICE BOB
12
Copy-modify-merge strategy
Sword and spear >>>>>>>>>>>>>
Wall of shields Sword and spear
Wall of shields
Bob push changes <<<<<<<<<<<<<
Standing strong
On this their chosen battle field
song.txt
Sword and spear Standing strong
Wall of shields On this their chosen battle field
ALICE BOB
13
Centralized vs Distributed
SERVER SERVER
version 5 push version 5 fetch
version 4 version 4
version 3 version 3
version 2 version 2
commit version 1 update version 1
COMPUTER 1 COMPUTER 2
version 5 version 5 merge
COMPUTER 1 COMPUTER 2 version 4 commit version 4
version 3 version 3
FILES FILES version 2 version 2
version 1 FILES version 1 FILES
14
Why Git
Version Control with Git. DevTestOps training.
Why Git
• Git is released under the GNU General Public License version 2.0,
which is an open source license. The Git project chose to use GPLv2
to guarantee your freedom to share and change free software - to
make sure the software is free for all its users.
16
Git benefits
17
Download,
install, configure
Version Control with Git. DevTestOps training.
Download, install, configure
D O W N L O A D & I N S TA L L CONFIGURE
• Download binary from here: http://git-scm.com/downloads • Generate SSH key pair
• Follow the steps using the default options ssh-keygen -t rsa –C “
[email protected]"
• Send public key to repository owner or upload to your profile
• Configure username and email
git config --global user.name “Vitali Shulha“
19
Create a github
repo and clone it
Version Control with Git. DevTestOps training.
Create github repository and clone it
• Simple as it can be
• Don’t forget to select “Initialize this repository with a README”
21
Create github repository
22
Cloning the repository
Select folder
Check content
Clone repo
Ensure it’s done
Go to target dir
See master branch
See content
23
Commit and push
Version Control with Git. DevTestOps training.
Making a first commit
Write line in text file
Write another line
Check the result
Add file to staging area
Commit the staged files
See the commit done
25
Push in to github
Check link to github.com
Push the commits to remote
26
Pull from remote
Version Control with Git. DevTestOps training.
Create commit in github and pull it
Edit file in web
Add new lines in the song
Commit changes
28
Create commit in github and pull it
Ensure the commit done
Pull code from github
See the changes arrived
29
Git GUI & gitk
Version Control with Git. DevTestOps training.
Undoing changes
Version Control with Git. DevTestOps training.
Undoing changes
Working directory FILE SYSTEM
git checkout -- file.txt
git checkout .
git clean -xdf
Staging area (Index)
git reset -- file.txt INDEX (STAGING AREA)
Local branch
git reset HEAD^^ (HEAD~2)
git commit --amend -m “commit message” COMMIT
Remote repository
git revert <sha1> REMOTE REPOSITORY
32
Git revert
Version Control with Git. DevTestOps training.
Undoing changes
Working directory FILE SYSTEM
git checkout -- file.txt
git checkout .
git clean -xdf
Staging area (Index)
git reset -- file.txt INDEX (STAGING AREA)
Local branch
git reset HEAD^^ (HEAD~2)
git commit --amend -m “commit message” COMMIT
Remote repository
git revert <sha1> REMOTE REPOSITORY
34
Git reset
Version Control with Git. DevTestOps training.
Git reset
FILE SYSTEM
git add
INDEX (STAGING AREA) git reset --mixed
git commit git reset --soft
COMMIT
git reset --hard
36
.gitignore
Version Control with Git. DevTestOps training.
.gitignore
# no .log files
*.log
# but do track error.log, even though you're
ignoring .log files above
!error.log
# only ignore the TODO file in the current
directory, not subdir/TODO
/TODO
# ignore all files in the build/ directory
build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
# ignore all .pdf files in the doc/ directory
doc/**/*.pdf
38
Branching and
merge
Version Control with Git. DevTestOps training.
Branch concept
Small feature
master
A B C D
Large feature
40
Fast-forward merge
HEAD
master
in feature
A B C
D E F
HEAD feature
in master
41
Fast-forward merge
HEAD
in feature
A B C
master
D E F
feature
HEAD
in master
42
Non fast-forward merge
HEAD
in master
master
A B C D
F G H
feature
HEAD
in feature
43
Non fast-forward merge
HEAD
in master
master
A B C D X
feature
F G H
HEAD
in feature
44
Conflict solving
Version Control with Git. DevTestOps training.
Conflicts solving
S O LV E C O N F L I C T AVO I D C O N F L I C T
Abort merge • Short commits
git merge --abort
• No edits to whitespaces
Resolve by selecting version • Merge often
git checkout --Xours --Xtheirs
Resolve manually
git diff
Undo merge
git revert 09fe472
User merge tool
46
Rebase
Version Control with Git. DevTestOps training.
Rebase
master
A B C
1 2
HEAD feature
in master
HEAD
in feature
48
Rebase
master
A B C D E
1 2
HEAD feature
in master
HEAD
in feature
49
Rebase
master
A B C D E
1 2
HEAD feature
in master
HEAD
in feature
50
Golden rule of Rebase
master
A B C 1 2 D E
HEAD
in master
JUST DON’T DO IT
51
Cherry-pick
Version Control with Git. DevTestOps training.
Cherry pick
master
A B C D E
1 2
HEAD feature
in master
HEAD
in feature
53
Cherry-pick
master
A B C D E
1 2 D
HEAD
in master feature
HEAD
in feature
54
Tags
Version Control with Git. DevTestOps training.
Tags
ver1 ver2
A B C D E F G
Mark commit with tag
git tag ver1
View tags
git tag –list
Push
git push --tags
Check it out
git checkout ver1
56
Stashing
Version Control with Git. DevTestOps training.
Stash
master
A B C D E
Save working directory
git stash save “description” 1 2 WIP
View stashes
git stash list
Bring them back feature
git stash pop (and remove from stash)
git stash apply (leave in stash)
Remove
git stash drop (clear)
58
Remotes
Version Control with Git. DevTestOps training.
Remotes
git push
local master origin master
git fetch
git push
local feature origin feature
git fetch
Add
git remote add <name> <url>
git remote add origin [email protected]:user/repo.git
View
git remote –v
git remote show <name>
60
Branching
strategies
Version Control with Git. DevTestOps training.
Centralized strategy
Bob’s commit
master
A B C D E F G
Eva’s commit
Alice’s commit
62
Feature-branch workflow
Small feature
master
A B C D
Large feature
63
Gitflow
Original post by Vincent Driessen: https://nvie.com/posts/a-successful-git-branching-model/
64
Integration manager workflow
blessed developer developer
repository public public
integration developer developer
manager private private
65
Dictator and Lieutenants workflow
blessed
dictator
repository
lieutenant lieutenant
developer developer developer
public private private
66
Forking workflow
original
repository forked forked
repository 1 repository 2
pull request 1 pull request 2
original
developer
A B C D E F
fork 1 fork 1
developer developer
67
Inside .git folder
Version Control with Git. DevTestOps training.
Commit, tree, blob
d2d84 629eb 55ec7
commit 2 tree README.md
73b39 bd35f abb54
commit 1 tree song.txt
• git show -s --pretty=raw d2d84
• git ls-tree 629eb
• git show abb54
69
Extras
Version Control with Git. DevTestOps training.
Extras
EXTRAS READ MORE
• git config -- global user.name “Vitali Shulha” • Pro Git by Scott Chacon and Ben Straub
• git config -- global user.email
“
[email protected]” • Version Control with Git by Jon Loeliger, Matthew McCullough
• git config --global core.editor "'C:/Program
Files (x86)/Notepad++/notepad++.exe‘”
• git blame
• git bisect
• git log --pretty=oneline
• git log --pretty=format:"%h %s" –graph
• git config --global alias.last 'log -1 HEAD‘
• git last
• git log master..experiment
• git filter-branch --tree-filter 'rm -f
passwords.txt' HEAD
• git rerere
• git submodule
71