Git tutorial II

Post on 01-Dec-2014

62 views 2 download

description

Git tutorial II

Transcript of Git tutorial II

Git Tutorial IIJim Yeh

Outline

• Review

• Collaboration

• Merge

• Rebase

• Simple GUI Demo

• Working on GitHub

Review

Commands (I)

• git clone <repository>

• git status

• git log

• git diff

Commands (II)

• git add <files>

• git commit

• git branch <branch>

• git checkout <branch>

• git pull <remote> <branch>

• git push <remote> <branch>

Commit Cycle

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

• git add

• git commit

Collaboration

Methods

• Merge

• Rebase

Merge

• A common option

• A complicated branch (tree)

Fetch & Pull

• git fetch - Update remote branches

• git pull - Update remote branches and current branch

Merge Cycle

• Checkout master

• Pull

• Merge

• Push

Initial

Merge Cycle

• Checkout master

• Pull

• Merge

• Push

Initial

Your branch

Merge Cycle

• Checkout master

• Pull

• Merge

• Push

Initial

Your branchAfter Pull

Merge Cycle

• Checkout master

• Pull

• Merge

• Push

Initial

Your branchAfter Pull

Merge

Merge Cycle

• Checkout master

• Pull

• Merge

• Push

Initial

Your branchAfter Pull

Merge

Remote

Push

Merge Cycle

Initial

Your branchAfter Pull

Merge

Remote

Push

• git checkout master

• git pull

• git merge <your branch>

• git push origin master

Conflict!

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

• Add updated files

• Commit

git log --graph

Push failed

Try: git pull

Exercise 5

• Add your introduction at the bottom of introduction.txt

• Checkout master

• Pull

• git merge <your branch>

• Fix conflict

• Push

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

Git Stash

• Stock your local difference (A queue)

• Prevent conflict on git pull

• Make branch be clean

Git Stash

• git stash

• git stash list

• git stash pop

• git stash drop

Rebase

• Trees are clean

• Work on single branch

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

Rebase• git pull --rebase

Rebase Flow

• git commit

• git pull --rebase

• Fix conflict

• git add <fixed filename>

• git rebase --continue

• git push

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

Merge / Rebase

• Choose the one you preferred.

• Merge is the default option.

• Rebase is more clean.

Git GUI Client

• GitHub

• SourceTree

Working on GitHub

• Fork

• Pull Request

Fork / Pull Request

Someone’s Repo A cloned Repo

New commit in your RepoPull request

Merge

Fork

Update / Commit / Push

Pull request

Exercise 7

• Fork git-exercise-2

• Create files for comments to this session

• Commit / Push

• Pull request

Q & A