CSE 391
Git branches, merging
Remote repositories
Slides created by Josh Ervin and Hunter Schafer. �Based off slides made by Marty Stepp, Jessica Miller, Ruth Anderson, Brett Wortzman, and Zorah Fung
AGENDA
ROADMAP
REVIEW: FOUR PHASES
Working Directory
Staging Area/Index
Local Repository
Remote Repository
Working changes
Changes you’re preparing to commit
Local copy of the repository with your committed changes
Remote shared repository (Usually stored with a platform like GitHub/Gitlab)
GIT: BRANCHING
NOTE: On most newer repos, master has been renamed to main. In practice you will see both names used in documentation and repos.
COMMIT HISTORY
A
B
C
These are commits. “A” is the first commit, “C” is the most recent
Each commit references it’s parent - the one that came before it in time.
master
HEAD
COMMIT HISTORY
A
B
C
master
HEAD
COMMIT HISTORY
A
B
C
master
HEAD
To view this same information on the command line:
$ git log
Or, to make it more similar to what we see here:
$ git log --graph --oneline
BRANCHING
A
B
C
master
HEAD
Commands that have been run:
$ git branch feature
$ git checkout feature
feature
BRANCHING
A
B
C
master
HEAD
Commands that have been run:
$ git branch feature
$ git checkout feature
$ echo “D” >> file.txt
$ git add file.txt
$ git commit -m “D”
feature
D
BRANCHING
A
B
C
master
Commands that have been run:
$ git branch feature
$ git checkout feature
$ echo “D” >> file.txt
$ git add file.txt
$ git commit -m “D”
$ git checkout master
$ echo “E” >> file.txt
$ git add file.txt
$ git commit -m “E”
feature
D
E
HEAD
BRANCHING
A
B
C
master
Commands that have been run:
$ git branch feature
$ git checkout feature
$ echo “D” >> file.txt
$ git add file.txt
$ git commit -m “D”
$ git checkout master
$ echo “E” >> file.txt
$ git add file.txt
$ git commit -m “E”
$ git merge feature
feature
D
E
M
HEAD
WORKING WITH REMOTE
A
B
master
Local
Remote
A
B
origin/master
master
HEAD
WORKING WITH REMOTE
A
B
master
Local
Remote
A
B
origin/master
C
master
HEAD
WORKING WITH REMOTE
A
B
master
Local
Remote
D
A
B
origin/master
C
master
HEAD
WORKING WITH REMOTE
A
B
master
Local
Remote
D
git push
A
B
origin/master
C
master
HEAD
WORKING WITH REMOTE
A
B
master
Local
Remote
D
git push
A
B
origin/master
C
master
HEAD
WORKING WITH REMOTE
A
B
A
B
master
Local
Remote
origin/master
C
master
HEAD
D
git fetch
D
WORKING WITH REMOTE
A
B
A
B
master
Local
Remote
origin/master
C
master
HEAD
D
D
git merge
M
Note: It’s more common to do git pull which is an alias for git fetch + get merge
WORKING WITH REMOTE
A
B
Local
Remote
origin/master
C
master
HEAD
D
M
git push
A
B
C
master
D
M
PULL REQUESTS
WORKING WITH REMOTE
Local
A
B
origin/master
C
master
HEAD
D
M
Remote
A
B
A
B
C
D
M
master
WORKING WITH REMOTE
Local
A
B
origin/master
C
master
D
M
X
feature
HEAD
Remote
A
B
A
B
C
D
M
master
WORKING WITH REMOTE
Local
Remote
A
B
A
B
origin/master
C
master
D
M
A
B
C
D
M
X
feature
HEAD
master
Y
Commit happens on origin
WORKING WITH REMOTE
Local
Remote
A
B
A
B
origin/master
C
master
D
M
A
B
C
D
M
X
feature
HEAD
master
Y
X
feature
git push feature
WORKING WITH REMOTE
Local
Remote
A
B
A
B
origin/master
C
master
D
M
A
B
C
D
M
X
feature
HEAD
master
Y
X
feature
Do this on GitLab
M1
WORKING WITH REMOTE
Local
Remote
A
B
A
B
origin/master
C
master
D
M
A
B
C
D
M
X
feature
HEAD
Y
X
M1
master
feature
M2
PULL REQUEST!!!