Git
Version Control System
Version Control System
• A way to keep track of changes to files (& folders)
• Between multiple authors (developers)
• A record of “who” did “what”, “when”
• “Why”, is provided by commit messages
Version Control System (Types)
• Centralized (Subversion, CVS)
• Server has the master repository, all commits go to the server
• Distributed (Git, Mercurial)
• Server has the master repository, but you have a copy (clone) of the
repository on your machine
Git is…
Git is…
• An open source VCS designed for speed and efficiency
• Created by Linus Torvalds (for managing Linux kernel)
• Hosted solutions include Github.com (more expensive) or
Bitbucket.com (cheaper)
• or running your own Git server
Moreover Git is…
• An open source, distributed version control software designed for
speed and efficiency
• Revisions (commits) you make to your local repository are available to
you only
• The next time you connect to the internet, push your changes to a
remote repository to share them
How it woks…
Remote Repo
Working Directory
Index
Repository
"Staging"
"a copy of your project"
git add
git commit
git push
/ git pull
internet
your pc
"your clone of the remote repo"
your edits
git clone
Git usages
Git usages : Understanding Git Workflow
Obtain a
repository
Make
some edits
Stage your
changes
Commit
your work
Push to
server
Git init
Git clone
Git pull
git commitgit add git push
Git pull
edits
git add git add git add
edits editsgit
commit
git
commit git
commit
Repo
Work
Stage
Repo
Work
Stage
Repo
Work
Stage
Repo
--> time -->
Origin
git clone
git pull
Origin
git
push
(git init)
internet
your pc
Git usages : Branches
•Why do branches matter? An example to
illustrate...
• Monday: You put all the client's code into a repo,
clone it locally
• Tuesday: You create a branch to implement a new
feature, making several commits
Git usages : Branches
• Wednesday: You realize that it would be better to
split out the feature into a couple different include
files, so you create 2 new files and delete the old
one. You commit your work.
• Thursday: The client contacts you frantically
wanting a hot fix for an issue discovered on the
version of the code on the live site.
Git usages : Branches
•What do you do now?
• You deleted their version of the file on
Wednesday, right?
• No! You made a branch.
• Their original file is in the master branch still!
Git usages : Branches
• Why:
• Try out an idea - experiment
• Isolate work units - keep unfinished work separate
• Work on long-running topics - come back to things later
• Share your work in progress with others without altering
the code in production or in development (remote feature
branches)
Branch Workflow
git branch "Branch"
git checkout Branch
git checkout Master
git merge Branch
edits
git add git add git add
edits edits
git
commit
git
commit
git
commit
Master
Branch
Work
Stage
Branch
Work
Stage
Branch
Work
Stage
Master
Branch
--> time -->
Origin
git clone
git pull
Origin
git push
internet
your pc
vs
• Centralized Version
Control Systems
(DVCS)
 Central, authoritative repository
 All changes saved in one single
location
• Distributed Version
Control Systems (DVCS)
 Clients can make changes in the
repositories and those changes will be
local to them.
SVN Dataflow Git Data Flow
Working
Dir
Remote
Repository
Online Source Control
 User must be online in order to
commit to the repository from
the working copy.
Offline Source Control
 Clients can commit changes to their
localized repositories as new
revisions even while being offline
Longer time to store
because all of the
data is stored in a
centralized repository.
 Extremely Fast
Complete copy of the data is stored
locally in the client’s system
 SVN help is more
organized
 There is some time wasted
since it is difficult to get a
quick reference from Git’s
search.
Creating and working
on branch/Merge is
complex and difficult to
use
Simple and Easy to use
branch and Merge
The working directory of
a developer is itself a
branch.
Sequencial Commits
 Data is lost when simultaneous
commits of two or more working
copies are performed
Non-Sequencial Commits
 Large number of users can put data to
the same repository
 No need to worry about data lost or
immediate merging of others changes
Revision Tracking
 SVN keeps record of files
 File history is lost on renaming
 Fixed by giving a file unique
long lived id
Revision Tracking
 Git keeps track of contents.
 Even a small change in content it tracks
it as a separate change.
Particially Checkout
 Checkouts at subdirectory level are
possible.
Only Full Checkout
 Git will not allow you to checkout a
subdirectory.
Simple usablity
 Simpler to learn
• create, commit and checkout
 Single central "master-repository”
Complex usablity
 Two modes of creating repositories
• checkout vs. clone
• commit vs. push.
 Git has more concepts and more
commands.
 many Git commands are cryptic, and
error messages are very user-unfriendly
Projects using SVN Projects using Git
BitBucket
Gitorious
Codeplex
Thank you for your attention