+ All Categories
Home > Documents > CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen...

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

Date post: 23-Aug-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
63
CS 241: Systems Programming Lecture 34. Advanced Git Fall 2019 Prof. Stephen Checkoway 1
Transcript
Page 1: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

CS 241: Systems Programming Lecture 34. Advanced Git

Fall 2019Prof. Stephen Checkoway

1

Page 2: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

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

Page 3: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

BranchesVisualize 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

Page 4: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Git branchingList all branches in the project‣ git branch

Create a new branch‣ git branch <branchname>

Switch to a branch‣ git checkout <branchname>

Create and immediately switch‣ git checkout –b <branchname>

Delete a branch‣ git branch –d <branchname>

4

Page 5: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Using branchesCreate and switch to a branch

5

$ git branch working

$ git checkout workingM READMESwitched to branch 'working'

$ git branch master* working

Page 6: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

StashingWorking 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

Page 7: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Using branches

7

Page 8: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Using branchesIntegrate changes back into master

8

$ git checkout masterSwitched to branch 'master'

$ git merge workingMerge made by the 'recursive' strategy. newfile.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 newfile.txt

Page 9: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Before git merge

9

Page 10: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

After git merge

10

Page 11: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Merged history

11

* 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

Page 12: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

RebasingLike 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

Page 13: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Before git rebase

13

Page 14: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

After git rebase

14

’ ’ ’

Page 15: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

git rebasePowerful tool

Can change the commit order

Merge/split commits

Make fixes in earlier commits‣ DO NOT DO ON PUSHED CHANGES OR PUBLIC BRANCH

15

$ git rebase –i master

Page 16: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Conflicts

16

Page 17: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Git conflict markers

17

$ cat foo.c<<<<<<< HEADcurrent content=======branch content>>>>>>> newbranch$ vim foo.c$ git add foo.c$ git rebase --continue

Page 18: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Pull requests with GithubContributing changes to repositories on Github

Requests the owner of the code integrate your changes

18

Page 19: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Setup

GitHub

19

Page 20: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Setup

upstream(theirs)

20

Page 21: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Setup

upstream(theirs)

fork

21

Page 22: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Setup

upstream(theirs)

origin(yours)

fork

22

Page 23: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Setup

upstream(theirs)

origin(yours)

clon

e

fork

23

Page 24: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Setup

upstream(theirs)

origin(yours)

local(yours)

clon

e

fork

24

Page 25: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Setup

upstream(theirs)

origin(yours)

local(yours)

upstreamclon

e

fork

25

Page 26: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Setup

upstream(theirs)

origin(yours)

local(yours)

origin upstream

26

Page 27: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Contribute Changes

upstream(theirs)

origin(yours)

local(yours)

origin upstream

27

Page 28: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Contribute Changes

upstream(theirs)

origin(yours)

local(yours)

origin upstreampush

28

Page 29: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Contribute Changes

upstream(theirs)

origin(yours)

local(yours)

origin upstreampush

29

Page 30: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Contribute Changes

upstream(theirs)

origin(yours)

local(yours)

origin upstreampush

pull request

30

Page 31: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Contribute Changes

upstream(theirs)

origin(yours)

local(yours)

origin upstreampush

pull request

31

Page 32: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Integrate Changes

upstream(theirs)

origin(yours)

local(yours)

origin upstream

32

Page 33: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Integrate Changes

upstream(theirs)

origin(yours)

local(yours)

origin upstreamfetch

33

Page 34: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Integrate Changes

upstream(theirs)

origin(yours)

local(yours)

origin upstreamfetch

34

Page 35: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Integrate Changes

upstream(theirs)

origin(yours)

local(yours)

origin upstreampush fetch

35

Page 36: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

Integrate Changes

upstream(theirs)

origin(yours)

local(yours)

origin upstreampush fetch

36

Page 37: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

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

Page 38: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master master

master

Branches

38

Page 39: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master master

master

$ git checkout -b feature

feature

39

Page 40: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master master

master

$ git commit

feature

40

Page 41: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master master

master

$ git push -u origin feature

feature

feature

41

Page 42: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master master

masterfeature

featurepull request

42

Page 43: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master master

master

Great idea, now can you do it more like this?

feature

featurepull request

43

Page 44: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master master

master

$ git commit$ git push

feature

feature

pull request

44

Page 45: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

mastermaster

master

Awesome, but please update with new changes in master

feature

feature

pull request

45

Page 46: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

mastermaster

master

$ git remote add upstream https://github.com/…$ git fetch upstream master:master

feature

feature

pull request

46

Page 47: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

mastermaster

master

$ git rebase master

feature

feature

pull request

WARNING:You may have

to resolve conflicts.

47

Page 48: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

mastermaster

master

$ git rebase master

feature

feature

pull request

48

Page 49: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master

master

$ git push -f origin master feature

feature

pull request

master

feature

49

Page 50: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master

master

feature

pull request

master

feature

Great. Please squash your commits.

50

Page 51: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master

master

$ git rebase –i master

feature

pull request

master

feature

51

Page 52: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master

master

$ git rebase –i master

feature

pull request

master

feature

52

Page 53: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master

master

$ git rebase –i master

feature

pull request

master

feature

53

Page 54: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master

master

$ git push -f origin feature

feature

pull request

masterfeature

54

Page 55: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master

masterfeature

pull request

masterfeature

Perfect, I accept!

55

Page 56: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master

master

Time to Clean Up

feature

masterfeature

56

Page 57: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master

master

I accept!

feature

masterfeature

$ git fetch upstream master:master

57

Page 58: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master

master

I accept!

feature

master feature

$ git push origin master

58

Page 59: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master

master

I accept!

master feature

$ git checkout master $ git branch -d feature

59

Page 60: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

origin upstream

local

master

master

I accept!

master

$ git push origin -d feature

60

Page 61: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

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

Page 62: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

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

Page 63: CS 241: Systems Programming Lecture 34. Advanced Git · Advanced Git Fall 2019 Prof. Stephen Checkoway 1. Using "branches" Development and release versions ... Rebasing Like merging,

In-class exercisehttps://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


Recommended