111
for me, for you.

Git introduction workshop for scientists

  • Upload
    winawer

  • View
    281

  • Download
    1

Embed Size (px)

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

Page 1: Git introduction workshop for scientists

for me, for you.

Page 2: Git introduction workshop for scientists

Git is version control.

Page 3: Git introduction workshop for scientists

What is version control?

Page 4: Git introduction workshop for scientists

The problem:

BackupsOrganizationCollaboration

Page 5: Git introduction workshop for scientists

h!p://www.phdcomics.com/comics/archive.php?comicid=1531

Page 6: Git introduction workshop for scientists
Page 7: Git introduction workshop for scientists

Thesis Thesis Thesis

Page 8: Git introduction workshop for scientists

v1 v7-3v43_SN_comments_Sept_27_response

Page 9: Git introduction workshop for scientists

Thesis_Final

Sept17_2013 Oct12_2013 Jan07_2014

Page 10: Git introduction workshop for scientists
Page 11: Git introduction workshop for scientists

Manuscript

FinalVersion Nature_Sub ObscureJournal

Page 12: Git introduction workshop for scientists

1

Page 13: Git introduction workshop for scientists

1 2

Page 14: Git introduction workshop for scientists

1 2

Page 15: Git introduction workshop for scientists

1 2

Page 16: Git introduction workshop for scientists
Page 17: Git introduction workshop for scientists

git commit -m "Initial commit."

the program

the git command

the command options git commit add checkout reset branch merge clone pull push

Page 18: Git introduction workshop for scientists
Page 19: Git introduction workshop for scientists

Manuscript

manuscript.tex

Figure1.pdf

Figure2.pdf

Page 20: Git introduction workshop for scientists

repository

Page 21: Git introduction workshop for scientists

Outboxstaging area

Page 22: Git introduction workshop for scientists

working copy

Page 23: Git introduction workshop for scientists

Manuscript

git checkout …

Page 24: Git introduction workshop for scientists

Outbox

manuscript.tex

• added 2 paragraphs• deleted 3 lines• moved 4 lines down• ...

git add …

Page 25: Git introduction workshop for scientists

git commit …

Outbox

commit: 83296a31...author: Steven HamblinDate: Friday May 9, 20:03:39 2014

Fixed introduction in manuscript.tex

Page 26: Git introduction workshop for scientists

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 …

Page 27: Git introduction workshop for scientists

Let’s try it.

Page 28: Git introduction workshop for scientists
Page 29: Git introduction workshop for scientists

Outbox

manuscript.tex

• added 2 paragraphs• deleted 3 lines• moved 4 lines down• ...

git add …

Page 30: Git introduction workshop for scientists
Page 31: Git introduction workshop for scientists

git commit …

Outbox

commit: 83296a31...author: Steven HamblinDate: Friday May 9, 20:03:39 2014

Fixed introduction in manuscript.tex

Page 32: Git introduction workshop for scientists
Page 33: Git introduction workshop for scientists
Page 34: Git introduction workshop for scientists

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...

Page 35: Git introduction workshop for scientists
Page 36: Git introduction workshop for scientists
Page 37: Git introduction workshop for scientists
Page 38: Git introduction workshop for scientists

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 —>

Page 39: Git introduction workshop for scientists
Page 40: Git introduction workshop for scientists
Page 41: Git introduction workshop for scientists

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

Page 42: Git introduction workshop for scientists

Branching.

Page 43: Git introduction workshop for scientists
Page 44: Git introduction workshop for scientists

Snapshot CSnapshot BSnapshot A

de102 d0100 c315c

master

Page 45: Git introduction workshop for scientists
Page 46: Git introduction workshop for scientists

de102 d0100 c315c

master

PNAS

Page 47: Git introduction workshop for scientists
Page 48: Git introduction workshop for scientists

de102 d0100 c315c

master

PNAS

HEAD

Page 49: Git introduction workshop for scientists

Manuscript

master

PNAS

git checkout

Page 50: Git introduction workshop for scientists
Page 51: Git introduction workshop for scientists

de102 d0100 c315c

master

PNAS

HEAD

Page 52: Git introduction workshop for scientists
Page 53: Git introduction workshop for scientists
Page 54: Git introduction workshop for scientists
Page 55: Git introduction workshop for scientists

de102 d0100 c315c

master

PNAS

HEAD

fc547

Page 56: Git introduction workshop for scientists
Page 57: Git introduction workshop for scientists

de102 d0100 c315c

master

PNAS

HEAD

fc547

Page 58: Git introduction workshop for scientists
Page 59: Git introduction workshop for scientists
Page 60: Git introduction workshop for scientists

de102 d0100 c315c

master

PNAS

HEAD

fc547

b755a

Page 61: Git introduction workshop for scientists
Page 62: Git introduction workshop for scientists
Page 63: Git introduction workshop for scientists
Page 64: Git introduction workshop for scientists

de102 d0100 c315c

master

PNAS

HEAD

fc547

b755a 20bb1

Page 65: Git introduction workshop for scientists

Exercise

Try this command: !

git log --graph --pretty --abbrev-commit

Page 66: Git introduction workshop for scientists

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.

Page 67: Git introduction workshop for scientists
Page 68: Git introduction workshop for scientists

Exercise

1. Now, checkout master again. 2. Merge the PNAS branch into

master again.

Page 69: Git introduction workshop for scientists
Page 70: Git introduction workshop for scientists

Commit early, commit o!en!

Branch early, branch o!en!

Page 71: Git introduction workshop for scientists

d0100

git reset git revert git diff

Page 72: Git introduction workshop for scientists

git reset - - hard <commit>git reset - - so! <commit>

Page 73: Git introduction workshop for scientists

git reset - - hard <commit>git reset - - so! <commit>

- -hard throws away changes, moves HEAD - -so! keeps changes, moves HEAD

Page 74: Git introduction workshop for scientists
Page 75: Git introduction workshop for scientists
Page 76: Git introduction workshop for scientists
Page 77: Git introduction workshop for scientists
Page 78: Git introduction workshop for scientists

de102 d0100 c315c

master

HEAD

b755a

Page 79: Git introduction workshop for scientists

de102 d0100 c315c

master

HEAD

deleted

Page 80: Git introduction workshop for scientists
Page 81: Git introduction workshop for scientists
Page 82: Git introduction workshop for scientists
Page 83: Git introduction workshop for scientists

Exercise

1. Make changes and commit, twice. 2. Make uncommi#ed changes. 3. Use git reset to throw away the

uncommi#ed changes.

Page 84: Git introduction workshop for scientists

Exercise

1. Make more uncommi#ed changes. 2. Use git reset to roll back the

repository without losing the uncommi!ed changes.

Page 85: Git introduction workshop for scientists

git stash

Page 86: Git introduction workshop for scientists
Page 87: Git introduction workshop for scientists
Page 88: Git introduction workshop for scientists
Page 89: Git introduction workshop for scientists
Page 90: Git introduction workshop for scientists

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.

Page 91: Git introduction workshop for scientists

Collaboration

1 2

Page 92: Git introduction workshop for scientists

user 1's local repository

user 2's local repository

user 1 user 2

remote repositorye.g. GitHub, Bitbucket

Page 93: Git introduction workshop for scientists

git clone

Page 94: Git introduction workshop for scientists
Page 95: Git introduction workshop for scientists

C1

Outbox

git push

Page 96: Git introduction workshop for scientists
Page 97: Git introduction workshop for scientists
Page 98: Git introduction workshop for scientists

git pull

Page 99: Git introduction workshop for scientists

git pullfe

tch

merge

Page 100: Git introduction workshop for scientists
Page 101: Git introduction workshop for scientists

Exercise

1. Create a GitHub account (github.com)

2. Create a repository on GitHub. 3. Clone the repository to your

machine.

Page 102: Git introduction workshop for scientists
Page 103: Git introduction workshop for scientists
Page 104: Git introduction workshop for scientists
Page 105: Git introduction workshop for scientists
Page 106: Git introduction workshop for scientists

Exercise

1. Make some local changes and commit them.

2. Push the changes to your remote repository.

Page 107: Git introduction workshop for scientists

Exercise

1. Go to github.com and make some changes on the remote side.

2. Pull the changes into your local.

Page 108: Git introduction workshop for scientists

Exercise

1. Advanced: change the same file locally and remotely to create a merge conflict.

2. Pull and resolve the conflict.

Page 109: Git introduction workshop for scientists

Exercise

1. Go to h#p://pco#le.github.io/learnGitBranching/

2. Do the “Main” Introduction sequence and the first “Remote” sequence.

Page 110: Git introduction workshop for scientists

Share and enjoy!

Page 111: Git introduction workshop for scientists

Steven Hamblin ([email protected])

h!p://winawer.org