git tutorial ii

34
Git Tutorial II Jim Yeh

Upload: chang-ching-yeh

Post on 01-Dec-2014

60 views

Category:

Technology


2 download

DESCRIPTION

Git tutorial II

TRANSCRIPT

Page 1: Git tutorial II

Git Tutorial IIJim Yeh

Page 2: Git tutorial II

Outline

• Review

• Collaboration

• Merge

• Rebase

• Simple GUI Demo

• Working on GitHub

Page 3: Git tutorial II

Review

Page 4: Git tutorial II

Commands (I)

• git clone <repository>

• git status

• git log

• git diff

Page 5: Git tutorial II

Commands (II)

• git add <files>

• git commit

• git branch <branch>

• git checkout <branch>

• git pull <remote> <branch>

• git push <remote> <branch>

Page 6: Git tutorial II

Commit Cycle

• Update file(Open the file and update its content manually)

• git add

• git commit

Page 7: Git tutorial II

Collaboration

Page 8: Git tutorial II

Methods

• Merge

• Rebase

Page 9: Git tutorial II

Merge

• A common option

• A complicated branch (tree)

Page 10: Git tutorial II

Fetch & Pull

• git fetch - Update remote branches

• git pull - Update remote branches and current branch

Page 11: Git tutorial II

Merge Cycle

• Checkout master

• Pull

• Merge

• Push

Initial

Page 12: Git tutorial II

Merge Cycle

• Checkout master

• Pull

• Merge

• Push

Initial

Your branch

Page 13: Git tutorial II

Merge Cycle

• Checkout master

• Pull

• Merge

• Push

Initial

Your branchAfter Pull

Page 14: Git tutorial II

Merge Cycle

• Checkout master

• Pull

• Merge

• Push

Initial

Your branchAfter Pull

Merge

Page 15: Git tutorial II

Merge Cycle

• Checkout master

• Pull

• Merge

• Push

Initial

Your branchAfter Pull

Merge

Remote

Push

Page 16: Git tutorial II

Merge Cycle

Initial

Your branchAfter Pull

Merge

Remote

Push

• git checkout master

• git pull

• git merge <your branch>

• git push origin master

Page 17: Git tutorial II

Conflict!

Page 18: Git tutorial II

Fix conflict• Find the conflict part and fix them: <<<<<<< HEADOriginal contents=======New contents>>>>>>> test_merge

• Add updated files

• Commit

Page 19: Git tutorial II

git log --graph

Page 20: Git tutorial II

Push failed

Try: git pull

Page 21: Git tutorial II

Exercise 5

• Add your introduction at the bottom of introduction.txt

• Checkout master

• Pull

• git merge <your branch>

• Fix conflict

• Push

Page 22: Git tutorial II

Exercise 5

• Add your introduction at the bottom of introduction.txt

• git checkout master

• git pull

• git merge <your branch>

• Fix conflict

• git push origin master

Page 23: Git tutorial II

Git Stash

• Stock your local difference (A queue)

• Prevent conflict on git pull

• Make branch be clean

Page 24: Git tutorial II

Git Stash

• git stash

• git stash list

• git stash pop

• git stash drop

Page 25: Git tutorial II

Rebase

• Trees are clean

• Work on single branch

• Each commit will be recreated. That is, the commit number and timestamp will change.

Page 26: Git tutorial II

Rebase• git pull --rebase

Page 27: Git tutorial II

Rebase Flow

• git commit

• git pull --rebase

• Fix conflict

• git add <fixed filename>

• git rebase --continue

• git push

Page 28: Git tutorial II

Exercise 6

• Checkout master branch

• Add your student id into ids file

• Commit

• Pull by rebase and fix conflict if necessary(git pull --rebase)

• Push

Page 29: Git tutorial II

Merge / Rebase

• Choose the one you preferred.

• Merge is the default option.

• Rebase is more clean.

Page 30: Git tutorial II

Git GUI Client

• GitHub

• SourceTree

Page 31: Git tutorial II

Working on GitHub

• Fork

• Pull Request

Page 32: Git tutorial II

Fork / Pull Request

Someone’s Repo A cloned Repo

New commit in your RepoPull request

Merge

Fork

Update / Commit / Push

Pull request

Page 33: Git tutorial II

Exercise 7

• Fork git-exercise-2

• Create files for comments to this session

• Commit / Push

• Pull request

Page 34: Git tutorial II

Q & A