Professional Documents
Culture Documents
Version Control: Git, Workflow & Tools
Version Control: Git, Workflow & Tools
Allows multiple users to work on the same file and merge changes
safely
Subversion (SVN)
Team Foundation Server (TFVC)
Perforce
Concurrent Versions System (CVS)
Git
Mercurial (Hg)
Bazaar
Bitkeeper
Darcs
Why distributed?
No single point of failure
If one developer machine explodes, other developers still have a complete
copy
Simple to restore
Git
Distributed version control system (DVCS)
Primarily command-line based
Getting Git
For Windows
Download installer from http://git-scm.com/download/win
Install
Select Use Git from the Windows Command Prompt option during
installation for optimal experience
Graphical frontends
Will be covering command line usage primarily, recommended you
learn this
Helps you better understand what is happening
If the command is long and archaic, you probably shouldnt be doing it!
Graphical tools exist, and do have some use-cases where they beat out
the command line
Check http://gitscm.com/downloads/guis for options
A personal recommendation would be TortoiseGit or SourceTree
In a terminal
git config --global user.name Cameron Grout
git config --global user.email cgrout@waikato.ac.nz
git config --global color.ui true
This tells git about you so that it can add this information to your commits
Useful for collaboration, you know who to contact about changes
These are global settings and act as defaults. You can set repository specific
settings if you want to maintain a personal/professional identity gap
COMP204-16B (HAM) - CAMERON GROUT
Git config?
The git application is actually a suite of commands
config is one of the sub-commands
Used for modifying configurations without diving in with a text editor
In a terminal, type
git init
10
The clone URL listed is just an example, yours will differ. You can use any
sort of path there, not just URLs
11
On a new repository, it will tell us that any files that were in the folder
need to be tracked
12
git add --all will tell git to track all new files and changes
git add *.java will tell git to track all new or changed .java files (note
the quotes)
When you want to remove a file from the repo, you need to indicate
this to git
git rm file.ext will tell git to stop tracking file.ext, and will delete to file
from disk
git rm --cached file.ext will tell git to stop tracking file.ext without
deleting it
COMP204-16B (HAM) - CAMERON GROUT
13
Taking a snapshot
Once you have told git about items that have been added, removed or
modified, you need to tell it to commit this to memory
git commit
This will prompt you to add a commit message by opening your editor
Can avoid this by supplying the commit message inline
git commit -m This is my commit message
Commit messages tell others (and you) what changed between the
current and previous commit
Helpful for working out when a bug was fixed (or not)
14
Before you take a snapshot, you have to arrange (stage) the shot
Just like with a camera, you dont just snap a picture
Frame and organize the scene before taking the picture
Once you have staged all the repository changes, you are ready to take a
snapshot
15
16
git log --stat will tell you what happened to which files
More verbose, useful when looking at a specific commit
git show <commit-id> will show the exact file changes for the specified
commit
This is an area where GUI tools excel
Picking specific commits to look at using the command line is clunky
17
Local workflow
init|clone ((add|rm|log|status)* commit)*
init/clone
status
add/rm
commit
log
18
Keep it granular so that you can easily track down where issues were
introduced
One commit with 200 lines of code changed isnt that helpful
Not too granular though, not one per line of code if not needed
19
Connecting to a remote
repository
Keep track of remote repositories using remotes that are stored in
your local repository
Can have as many of these as you like
If you cloned a repository, git will add the clone path as a remote
automatically named origin
If you initd your repository, you need to add the remote manually
git remote add <alias> <path>
git remote add origin http://gitlab.waikato.ac.nz/cgrout/GitIntroduction.git
You can now exchange files and changes with the remote
COMP204-16B (HAM) - CAMERON GROUT
20
Send the changes from master (local repo) to the origin (remote repo)
The -u stores the origin/master part, so in future you just use git push
Pulling is bringing changes from the remote repository to the local one
git pull origin master
Gets the changes from origin (remote repo) and brings them into master
(local)
21
recent commit
22
Dont need to specify the whole commit id, just enough to make the id
unambiguous
23
Repository permissions
If you dont have write permissions to a repository, you cant push to it
Makes collaboration annoying
Performs a deep copy of the repository, and puts the copy in your
namespace, giving you write permissions to the copy
Your copy remembers how it relates to the original, which makes
collaboration using pull requests/merge requests a lot nicer
Pull requests/merge requests outside of scope for now
COMP204-16B (HAM) - CAMERON GROUT
24
Experience it
We have set up a GitLab instance for you to use for this course
http://gitlab.cms.waikato.ac.nz/
Go here and sign in with your normal username, with the last 8-digits of your
student ID barcode as your password.
25
Important Note
We can, and intend to, look at your GitLab repositories. Setting your
repositories to private just means that other students cannot see them,
but it does not prevent us from looking in.
Keep this in mind when uploading files and content to your repos. If you
dont want us to see or read something, dont upload it!
26