Visualizing Git Workflows A visual guide to 539 workflows
Table of Contents Notation Collaboration Without Review or Branches Merge Conflicts Requesting Code Review Collaboration with Multiple Branches
Notation
Notation This is a single commit. The text is the commit ID. C4 This is a branch (i.e. sequence of commits). Each branch has a different color.
Notation These boxes show the state of a repository at a given location.
Notation C8 C4 This means that is storing two branches. One has 4 commits, the other has 3.
Notation C7 C8 C9 This means that s computer is storing local copies of the same two branches.
Notation C7 C8 C9 C7 C8 C4 Local Copy Remote Copy Same branches, different commits.
Notation I show branches like this: C4 C5 Other tutorials may show this: C5 C4 They mean the same thing
Collaboration Without Review or Branches
There is a master branch on github with two commits. Bob
clones the repository on her computer. Bob
Bob clones the repository on his computer. Bob
commits new code to her master branch Bob
pushes the feature branch to for all to see. Bob
Bob fetches s new changes from. Bob
Bob builds some of his code on s new commit. C4 Bob
C4 Bob pushes his code to for to see. C4 Bob
C4 pulls Bob s changes, so now everyone has the same code. C4 C4 Bob
Merge Conflicts What happens when we change the same file?
Imagine is fixing a bug. She starts by checking out a new purple branch, based off of her local master.
C4 Around the same time, bob pushes a new commit, C4, to master. Now the remote master (on ) is out of sync with s local master branch.
C4 creates a new commit, C5, to fix the bug on her new branch. C5
C4 Now pulls Bob s updated changes from to her computer. C4 C5 Bob put the new feature on the master branch, so when pulls, it goes to her local master branch. Notice how the last commit of the bug fix branch is different from master.
C4 Now adds her local bug fix to her local master branch. She does this by merging her changes from her bug fix branch to her master C4 C6 branch. C5 If there is a conflict with Bob s changes, this results in a special merge commit.
Requesting Code Review Do this for every change outside of SkunkWorks!
creates a new feature branch.
commits new code to her feature branch
pushes the feature branch to for all to see. She creates a pull request and asks for a review.
C4 C4 After addressing a few comments in a new commit, the Koz says Ayyyy that code looks good.
C4 After addresses any review comments and obtains approval, the Koz merges her changes to master. C4
C4 now pulls the new master from, and deletes her old branch. Now everyone has the same code. C4
Collaboration With Multiple branches
There is a master branch on github with two commits. Bob
Both and Bob clone the repository on their computers. Bob
creates a local orange branch. Bob creates a local purple branch. Bob
They both commit new code to each of their branches. C4 Bob
pushes the feature branch to for all to see. She requests a pull request. C4 Bob
The course staff merges s changes with the master branch on. C4 Bob
Both and Bob pull down the changes from master. C4 Bob
Bob merges master into his feature branch. C4 C6 Bob
C4 C6 Bob pushes his feature branch to master and asks for a PR. C4 C6 Bob