cs 241 systems programming lecture 34 advanced git
play

CS 241: Systems Programming Lecture 34. Advanced Git Fall 2019 - PowerPoint PPT Presentation

CS 241: Systems Programming Lecture 34. Advanced Git Fall 2019 Prof. Stephen Checkoway 1 Using "branches" Development and release versions Trying out new features Focusing on fixing a bug Simpler to do in Git than other VCS, consider


  1. CS 241: Systems Programming Lecture 34. Advanced Git Fall 2019 Prof. Stephen Checkoway 1

  2. Using "branches" Development and release versions Trying out new features Focusing on fixing a bug Simpler to do in Git than other VCS, consider using more frequently 2

  3. Branches Visualize a project’s development as a “linked list” of commits. When a development track splits, a new branch is created. In Git, branches are actually just a pointer to these commits 3

  4. Git branching List all branches in the project Create and immediately switch ‣ git branch ‣ git checkout –b <branchname> Create a new branch Delete a branch ‣ git branch <branchname> ‣ git branch –d <branchname> Switch to a branch ‣ git checkout <branchname> 4

  5. Using branches Create and switch to a branch $ git branch working $ git checkout working M README Switched to branch 'working' $ git branch master * working 5

  6. Stashing Working tree should be clean when switching branches Save/hide changes you don't want to commit with git stash ‣ Pushes changes onto a stash stack Recover changes lager with git stash pop 6

  7. Using branches 7

  8. Using branches Integrate changes back into master $ git checkout master Switched to branch 'master' $ git merge working Merge made by the 'recursive' strategy. newfile.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 newfile.txt 8

  9. Before git merge 9

  10. After git merge 10

  11. Merged history * cdd07b2 - (HEAD, master) Merge branch 'working' |\ | * 1ccf9e7 - (working) Added a new file * | 3637a76 - Second change * | cf98d00 - First change |/ * cf31a23 - Updated README to 2.0 * 2a8fc15 - Initial commit 11

  12. Rebasing Like merging, rebasing transfers changes from one branch to another Does not create a new commit Replays changes from current branch onto head of other branch 12

  13. Before git rebase 13

  14. After git rebase ’ ’ ’ 14

  15. git rebase Powerful tool Can change the commit order Merge/split commits Make fixes in earlier commits ‣ DO NOT DO ON PUSHED CHANGES OR PUBLIC BRANCH $ git rebase –i master 15

  16. Conflicts 16

  17. Git conflict markers $ cat foo.c <<<<<<< HEAD current content ======= branch content >>>>>>> newbranch $ vim foo.c $ git add foo.c $ git rebase --continue 17

  18. Pull requests with Github Contributing changes to repositories on Github Requests the owner of the code integrate your changes 18

  19. Setup GitHub 19

  20. Setup upstream 
 (theirs) 20

  21. Setup upstream 
 fork (theirs) 21

  22. Setup origin 
 upstream 
 fork (yours) (theirs) 22

  23. Setup origin 
 upstream 
 fork (yours) (theirs) clone 23

  24. Setup origin 
 upstream 
 fork (yours) (theirs) clone local 
 (yours) 24

  25. Setup origin 
 upstream 
 fork (yours) (theirs) clone upstream local 
 (yours) 25

  26. Setup origin 
 upstream 
 (yours) (theirs) upstream origin local 
 (yours) 26

  27. Contribute Changes origin 
 upstream 
 (yours) (theirs) upstream origin local 
 (yours) 27

  28. Contribute Changes origin 
 upstream 
 (yours) (theirs) push upstream origin local 
 (yours) 28

  29. Contribute Changes origin 
 upstream 
 (yours) (theirs) push upstream origin local 
 (yours) 29

  30. Contribute Changes pull origin 
 upstream 
 request (yours) (theirs) push upstream origin local 
 (yours) 30

  31. Contribute Changes pull origin 
 upstream 
 request (yours) (theirs) push upstream origin local 
 (yours) 31

  32. Integrate Changes origin 
 upstream 
 (yours) (theirs) upstream origin local 
 (yours) 32

  33. Integrate Changes origin 
 upstream 
 (yours) (theirs) fetch upstream origin local 
 (yours) 33

  34. Integrate Changes origin 
 upstream 
 (yours) (theirs) fetch upstream origin local 
 (yours) 34

  35. Integrate Changes origin 
 upstream 
 (yours) (theirs) fetch push upstream origin local 
 (yours) 35

  36. Integrate Changes origin 
 upstream 
 (yours) (theirs) fetch push upstream origin local 
 (yours) 36

  37. You want to contribute code to the Github project fancy/project ( fancy is the name of the owner, project is the name of the repo). You fork the repo (producing student/project ), commit your changes, and push to student/project . Next, you make a pull request for fancy/project . Which statement is true? A. Your code is now integrated into fancy/project via merging B. Your code is now integrated into fancy/project via rebasing C. You have requested that your code be integrated into fancy/project , but no changes have been made D. You cannot make any additional commits until the pull request has been accepted 37

  38. Branches origin upstream master master local master 38

  39. $ git checkout -b feature origin upstream master master local master feature 39

  40. $ git commit origin upstream master master feature local master 40

  41. $ git push -u origin feature origin upstream feature master master feature local master 41

  42. origin upstream feature master master pull request feature local master 42

  43. Great idea, now can you do it more like this? origin upstream feature master master pull request feature local master 43

  44. $ git commit $ git push feature origin upstream master master pull request feature local master 44

  45. Awesome, but please update with new changes in master feature origin upstream master master pull request feature local master 45

  46. $ git remote add upstream https://github.com/… $ git fetch upstream master:master feature origin upstream master master pull request feature master local 46

  47. $ git rebase master feature origin upstream master master pull request feature WARNING: 
 master local You may have 
 to resolve conflicts. 47

  48. $ git rebase master feature origin upstream master master pull request feature master local 48

  49. $ git push -f origin master feature feature origin upstream master master pull request feature master local 49

  50. Great. Please squash your commits. feature origin upstream master master pull request feature master local 50

  51. $ git rebase –i master feature origin upstream master master pull request feature master local 51

  52. $ git rebase –i master feature origin upstream master master pull request feature master local 52

  53. $ git rebase –i master feature origin upstream master master pull request feature master local 53

  54. $ git push -f origin feature feature origin upstream master master pull request feature master local 54

  55. Perfect, I accept! feature origin upstream master master pull request feature master local 55

  56. Time to Clean Up master feature origin upstream master feature master local 56

  57. I accept! $ git fetch upstream master:master master feature origin upstream master feature master local 57

  58. I accept! $ git push origin master master feature master origin upstream feature master local 58

  59. $ git checkout master 
 I accept! $ git branch -d feature master feature master origin upstream master local 59

  60. I accept! $ git push origin -d feature master master origin upstream master local 60

  61. After a PR is accepted, Github will ask you if you want to delete your feature branch. If you say yes, which branches get deleted? A. feature — the branch named feature in your local repo B. origin/feature — the branch named feature in your remote repo C. upstream/feature — the branch named feature in their remote repo D. feature and origin/feature E. feature , origin/feature , and upstream/feature 61

  62. Now that origin/feature has been deleted, how do you delete feature ? A. $ git delete feature B. $ git delete -b feature C. $ git branch -d feature D. $ git push origin -d feature E. I would google "delete a git branch" and then click on https:// stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch- locally-and-remotely like every other programmer 62

  63. In-class exercise https://checkoway.net/teaching/cs241/2019-fall/exercises/Lecture-34.html Grab a laptop and a partner and try to get as much of that done as you can! 63

Recommend


More recommend