2. What is a Version Control System (VCS)
a software utility that tracks and manages changes to a file system.
kind of "database". lets you save changes and take a look over time.
tracks the addition, deletion, and modification actions applied to files and
directories.
offers collaborative utilities to share and integrate these file system changes to
other VCS users.
3. Primary benefits of a VCS
A complete long-term change history of every file.
Branching and merging.
Traceability
4. Most popular version controls systems
Source : https://www.openhub.net/
VCS’s in Open Source Projects
6. “Tools” to get started with Git
Git itself. Download from official site https://git-scm.com/downloads
Git Bash. Convenient Command Prompt (Terminal) for Windows to run Git
commands and Unix commands such as cat, touch etc.
Git GUI Clients : GitHub Desktop, GitKraken, SmartGit, SourceTree, TortoiseGit.
Even more GUI clients at https://git-scm.com/downloads/guis
IDE integrated Git tools and plugins to work with Git. Most IDE’s have built in tools
or plugins to support Git.
7. Git basic commands
git init – initializes current directory as Git repository
git add - adds file(s) to “Staging Area”
git commit – creates new commit/version.
git status – shows the working tree (files & directories) status
git log – list commits
gitignore – prevent files and directories from being version controlled.
9. gitignore – Ignoring files
.gitignore file specifies files that Git should ignore
gitignore – specifies untracked files to ignore
only untracked files can be ignored
Files already tracked by Git are not affected
.gitignore uses globbing patterns to match against file names
untrack a file example : git rm --cached "New Microsoft Excel Worksheet.xlsx“
untrack all “dll” files : git rm --cached *.dll
10. gitignore – Ignoring files (Examples)
Pattern Explanation Example matches
**/logs logs directories anywhere
in the repository.
logs/debug.log
logs/monday/foo.bar
build/logs/debug.log
**/logs/debug.log All debug.log files which
are in logs directory
logs/debug.log
build/logs/debug.log
but not
logs/build/debug.log
*.log
!important.log
debug.log
trace.log
but not
important.log
logs/important.log
All log files but not
the files named
important.log
11. The staging area
git add - adds files, folders to the staging area
Examples : git add <file>, git add <directory>, git add hello.py, git add .
git commit – commits/saves files only existing in the staging area
The staging area stores information on what will go into your next commit
13. Branching out – Introduction 1
If you make some changes and commit again, the next commit stores a pointer to the
commit that came immediately before it.
A branch in Git is simply a lightweight movable pointer to one of these commits.
The default branch name in Git is master. git init command creates it by default and
most people don’t bother to change it.
14. Branching out – Introduction 2
Every time you commit, the current branch (initially master) pointer moves forward
automatically.
15. Branching out – Creating new branch
When you create a new branch it creates a new pointer pointing to the latest
commit.
to create a new branch called testing run this git branch command:
$ git branch testing
This creates a new pointer to the same commit you’re currently on.
16. Branching out – HEAD
How does Git know what branch you’re currently on?
It keeps a special pointer called HEAD
this is a pointer to the local branch you’re currently on
17. Branching out – Switching branches
To switch to the existing branch testing branch run the following command:
$ git checkout testing
This moves HEAD to point to the testing branch
18. Branching out - Advancing
After checking out testing branch let’s do another commit
HEAD branch moves forward when a commit is made
testing branch has moved forward
master branch still points to the commit it was on when switched branches
19. Branching out – Switching back
Let’s switch back to the master branch:
$ git checkout master
HEAD pointer is moved back to point to the master branch
the files in your working directory are reverted back to the snapshot that master
points to
20. Branching out – Diverging
After checking out master branch let’s do another commit
HEAD branch moves forward when a commit is made
master branch has moved forward
21. Branching out – Some commands
$ git branch – list branches
$ git branch develop – create new branch develop
$ git checkout develop – switch to develop branch
$ git checkout -b hotfix – create hotfix branch and switch to it
$ git branch -d issue1 – delete local branch issue1
$ git branch -m developer develop – rename developer branch into develop
23. Merging – Fast forwarding
Merging hotfix into master by running the following commands :
$ git checkout master
$ git merge hotfix
24. Merging – Delete merged branch
delete the hotfix branch, we longer need it, the master branch points at the same place
$ git branch -d hotfix
add new commit C5 in iss53 branch
25. Merging - Three-way merge
Merging iss53 into master
$ git checkout master
$ git merge iss53
Git does a simple three-way by using common ancestor (C2) and two snapshots
(C4 & C5)
26. Merge Conflicts
If you changed the same part of the same file differently in the two branches you’re
merging, Git won’t be able to merge them cleanly.
you’ll get a merge conflict that looks something like
$ git merge iss53
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
27. Merge Conflicts - Status
Anything that has merge conflicts and hasn’t been resolved is listed as unmerged.
If you want to see which files are unmerged at any point after a merge conflict, you can run git status:
$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: index.html
no changes added to commit (use "git add" and/or "git commit -a")
28. Merge Conflicts – Resolution markers
Git adds standard conflict-resolution markers to the files that have conflicts
you can open them manually and resolve those conflicts
your file contains a section that looks something like this:
<<<<<<< HEAD:index.html
<div id="footer">contact : email.support@github.com</div>
=======
<div id="footer">
please contact us at support@github.com
</div>
>>>>>>> iss53:index.html
29. Merge Conflicts - Finalization
Remove conflict-resolution markers
choose one side or the other or merge the contents yourself
to use a graphical tool to resolve these issues, you can run git mergetool
run git status again to verify that all conflicts have been resolved
type git commit to finalize the merge commit