CS 241: Systems Programming Lecture 34. Advanced Git
Fall 2019
- Prof. Stephen Checkoway
1
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
Fall 2019
1
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
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
List all branches in the project
Create a new branch
Switch to a branch
Create and immediately switch
Delete a branch
4
Create and switch to a branch
5
$ git branch working $ git checkout working M README Switched to branch 'working' $ git branch master * working
Working tree should be clean when switching branches Save/hide changes you don't want to commit with git stash
Recover changes lager with git stash pop
6
7
Integrate changes back into master
8
$ 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
9
10
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
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
14
Powerful tool Can change the commit order Merge/split commits Make fixes in earlier commits
15
$ git rebase –i master
16
17
$ cat foo.c <<<<<<< HEAD current content ======= branch content >>>>>>> newbranch $ vim foo.c $ git add foo.c $ git rebase --continue
Contributing changes to repositories on Github Requests the owner of the code integrate your changes
18
19
upstream (theirs)
20
upstream (theirs) fork
21
upstream (theirs)
(yours) fork
22
upstream (theirs)
(yours) clone fork
23
upstream (theirs)
(yours) local (yours) clone fork
24
upstream (theirs)
(yours) local (yours)
upstream
clone fork
25
upstream (theirs)
(yours) local (yours)
upstream
26
upstream (theirs)
(yours) local (yours)
upstream
27
upstream (theirs)
(yours) local (yours)
upstream push
28
upstream (theirs)
(yours) local (yours)
upstream push
29
upstream (theirs)
(yours) local (yours)
upstream push pull request
30
upstream (theirs)
(yours) local (yours)
upstream push pull request
31
upstream (theirs)
(yours) local (yours)
upstream
32
upstream (theirs)
(yours) local (yours)
upstream
33
upstream (theirs)
(yours) local (yours)
upstream
34
upstream (theirs)
(yours) local (yours)
upstream
push
35
upstream (theirs)
(yours) local (yours)
upstream
push
36
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?
but no changes have been made
accepted
37
upstream local master master master
38
upstream local master master master
feature
39
upstream local master master master
feature
40
upstream local master master master
feature feature
41
upstream local master master master feature feature
pull request
42
upstream local master master master
feature feature
pull request
43
upstream local master master master
feature feature
pull request
44
upstream local master master master
feature feature
pull request
45
upstream local master master master
feature feature
pull request
46
upstream local master master master
feature feature
pull request WARNING: You may have to resolve conflicts.
47
upstream local master master master
feature feature
pull request
48
upstream local master master
feature
pull request
master feature
49
upstream local master master feature
pull request
master feature
50
upstream local master master
feature
pull request
master feature
51
upstream local master master
feature
pull request
master feature
52
upstream local master master
feature
pull request
master feature
53
upstream local master master
feature
pull request
master feature
54
upstream local master master feature
pull request
master feature
55
upstream local master master
feature master feature
56
upstream local master master
feature master feature
57
upstream local master master
feature master feature
58
upstream local master master
master feature
59
upstream local master master
master
60
After a PR is accepted, Github will ask you if you want to delete your feature
61
Now that origin/feature has been deleted, how do you delete feature?
stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch- locally-and-remotely like every other programmer
62
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