View
281
Download
1
Category
Preview:
DESCRIPTION
These are the slides for a workshop I gave on June 2, 2014 at USC. They are an introduction to git and version control for my fellow scientists. Note that the branching section draws heavily on the diagrams and material from the Pro Git book (http://git-scm.com/book/), though I reimplemented them for my own uses.
Citation preview
for me, for you.
Git is version control.
What is version control?
The problem:
BackupsOrganizationCollaboration
h!p://www.phdcomics.com/comics/archive.php?comicid=1531
Thesis Thesis Thesis
v1 v7-3v43_SN_comments_Sept_27_response
Thesis_Final
Sept17_2013 Oct12_2013 Jan07_2014
Manuscript
FinalVersion Nature_Sub ObscureJournal
1
1 2
1 2
1 2
git commit -m "Initial commit."
the program
the git command
the command options git commit add checkout reset branch merge clone pull push
Manuscript
manuscript.tex
Figure1.pdf
Figure2.pdf
repository
Outboxstaging area
working copy
Manuscript
git checkout …
Outbox
manuscript.tex
• added 2 paragraphs• deleted 3 lines• moved 4 lines down• ...
git add …
git commit …
Outbox
commit: 83296a31...author: Steven HamblinDate: Friday May 9, 20:03:39 2014
Fixed introduction in manuscript.tex
Manuscript git checkout …
Outbox
manuscript.tex
• added 2 paragraphs• deleted 3 lines• moved 4 lines down• ...
git add …
Outbox
commit: 83296a31...author: Steven HamblinDate: Friday May 9, 20:03:39 2014
Fixed introduction in manuscript.texgit commit …
Let’s try it.
Outbox
manuscript.tex
• added 2 paragraphs• deleted 3 lines• moved 4 lines down• ...
git add …
git commit …
Outbox
commit: 83296a31...author: Steven HamblinDate: Friday May 9, 20:03:39 2014
Fixed introduction in manuscript.tex
commit size
treeauthorcommitter
09f0e...Steven
StevenInitial commit.
tree size
blobblobblob
25351 manuscript.txt
README.md
3a44f8762e
Figure1.pdf
blob size
This is going to be an AWESOME NATURE PAPER!
blob size
... binary data ...
blob size
## README
This is the README for my AWESOME NATURE PAPER.
de102...09f0e...
25351...
3a44f...
8762e...
git commit + git add
Outbox
commit: 83296a31...author: Steven HamblinDate: Friday May 9, 20:03:39 2014
Fixed introduction in manuscript.tex
Outbox
manuscript.tex
• added 2 paragraphs• deleted 3 lines• moved 4 lines down• ...
git commit -a —>
commit size
treeauthorcommitter
09f0e...Steven
StevenInitial commit.
de102...
commit size
tree
authorcommitter
47ae6...
Steven
StevenAdded my plan
d0100... c315c...
parent de102...
commit size
tree
authorcommitter
7cae3...
Steven
StevenAdded note of caution.
parent c315c...
Snapshot CSnapshot BSnapshot A
Branching.
Snapshot CSnapshot BSnapshot A
de102 d0100 c315c
master
de102 d0100 c315c
master
PNAS
de102 d0100 c315c
master
PNAS
HEAD
Manuscript
master
PNAS
git checkout
de102 d0100 c315c
master
PNAS
HEAD
de102 d0100 c315c
master
PNAS
HEAD
fc547
de102 d0100 c315c
master
PNAS
HEAD
fc547
de102 d0100 c315c
master
PNAS
HEAD
fc547
b755a
de102 d0100 c315c
master
PNAS
HEAD
fc547
b755a 20bb1
Exercise
Try this command: !
git log --graph --pretty --abbrev-commit
Exercise
1. Checkout the PNAS branch again. 2. Create a new file with some
references in it. Call it refs.txt. 3. Add the file, then commit it.
Exercise
1. Now, checkout master again. 2. Merge the PNAS branch into
master again.
Commit early, commit o!en!
Branch early, branch o!en!
d0100
git reset git revert git diff
git reset - - hard <commit>git reset - - so! <commit>
git reset - - hard <commit>git reset - - so! <commit>
- -hard throws away changes, moves HEAD - -so! keeps changes, moves HEAD
de102 d0100 c315c
master
HEAD
b755a
de102 d0100 c315c
master
HEAD
deleted
Exercise
1. Make changes and commit, twice. 2. Make uncommi#ed changes. 3. Use git reset to throw away the
uncommi#ed changes.
Exercise
1. Make more uncommi#ed changes. 2. Use git reset to roll back the
repository without losing the uncommi!ed changes.
git stash
Exercise
1. Make uncommi#ed changes. 2. Stash those changes 3. Switch branches. Make changes
and commit. 4. Switch back and retrieve your
stashed changes.
Collaboration
1 2
user 1's local repository
user 2's local repository
user 1 user 2
remote repositorye.g. GitHub, Bitbucket
git clone
C1
Outbox
git push
git pull
git pullfe
tch
merge
Exercise
1. Create a GitHub account (github.com)
2. Create a repository on GitHub. 3. Clone the repository to your
machine.
Exercise
1. Make some local changes and commit them.
2. Push the changes to your remote repository.
Exercise
1. Go to github.com and make some changes on the remote side.
2. Pull the changes into your local.
Exercise
1. Advanced: change the same file locally and remotely to create a merge conflict.
2. Pull and resolve the conflict.
Exercise
1. Go to h#p://pco#le.github.io/learnGitBranching/
2. Do the “Main” Introduction sequence and the first “Remote” sequence.
Share and enjoy!
Steven Hamblin (steven.hamblin@gmail.com)
h!p://winawer.org
Recommended