Git tutorial II
-
Upload
chang-ching-yeh -
Category
Technology
-
view
59 -
download
2
description
Transcript of Git tutorial II
![Page 1: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/1.jpg)
Git Tutorial IIJim Yeh
![Page 2: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/2.jpg)
Outline
• Review
• Collaboration
• Merge
• Rebase
• Simple GUI Demo
• Working on GitHub
![Page 3: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/3.jpg)
Review
![Page 4: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/4.jpg)
Commands (I)
• git clone <repository>
• git status
• git log
• git diff
![Page 5: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/5.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/6.jpg)
Commit Cycle
• Update file(Open the file and update its content manually)
• git add
• git commit
![Page 7: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/7.jpg)
Collaboration
![Page 8: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/8.jpg)
Methods
• Merge
• Rebase
![Page 9: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/9.jpg)
Merge
• A common option
• A complicated branch (tree)
![Page 10: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/10.jpg)
Fetch & Pull
• git fetch - Update remote branches
• git pull - Update remote branches and current branch
![Page 11: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/11.jpg)
Merge Cycle
• Checkout master
• Pull
• Merge
• Push
Initial
![Page 12: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/12.jpg)
Merge Cycle
• Checkout master
• Pull
• Merge
• Push
Initial
Your branch
![Page 13: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/13.jpg)
Merge Cycle
• Checkout master
• Pull
• Merge
• Push
Initial
Your branchAfter Pull
![Page 14: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/14.jpg)
Merge Cycle
• Checkout master
• Pull
• Merge
• Push
Initial
Your branchAfter Pull
Merge
![Page 15: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/15.jpg)
Merge Cycle
• Checkout master
• Pull
• Merge
• Push
Initial
Your branchAfter Pull
Merge
Remote
Push
![Page 16: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/16.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/17.jpg)
Conflict!
![Page 18: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/18.jpg)
Fix conflict• Find the conflict part and fix them: <<<<<<< HEADOriginal contents=======New contents>>>>>>> test_merge
• Add updated files
• Commit
![Page 19: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/19.jpg)
git log --graph
![Page 20: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/20.jpg)
Push failed
Try: git pull
![Page 21: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/21.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/22.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/23.jpg)
Git Stash
• Stock your local difference (A queue)
• Prevent conflict on git pull
• Make branch be clean
![Page 24: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/24.jpg)
Git Stash
• git stash
• git stash list
• git stash pop
• git stash drop
![Page 25: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/25.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/26.jpg)
Rebase• git pull --rebase
![Page 27: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/27.jpg)
Rebase Flow
• git commit
• git pull --rebase
• Fix conflict
• git add <fixed filename>
• git rebase --continue
• git push
![Page 28: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/28.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/29.jpg)
Merge / Rebase
• Choose the one you preferred.
• Merge is the default option.
• Rebase is more clean.
![Page 30: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/30.jpg)
Git GUI Client
• GitHub
• SourceTree
![Page 31: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/31.jpg)
Working on GitHub
• Fork
• Pull Request
![Page 32: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/32.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/33.jpg)
Exercise 7
• Fork git-exercise-2
• Create files for comments to this session
• Commit / Push
• Pull request
![Page 34: Git tutorial II](https://reader033.fdocuments.in/reader033/viewer/2022042606/547ed2a5b47959c5508b4c0d/html5/thumbnails/34.jpg)
Q & A