Collaboration with Git & GitHub

What life looks like for most of you

Commits are mostly linear

git commit → git push
origin/master
master
push
pull

You

Everyone else

git clone

Collaborating with Git

Git workflows

Centralized workflow

Centralized workflow

git pull before starting work

Everyone commits to master 

git push

If there is no merge conflict, 🙌

Otherwise fix merge conflict, then push

Feature branching workflow

Feature branching workflow

Create and switch to a branch

Add commits

Push feature branch to GitHub

Start a pull request

Discuss, add more commits, merge

git checkout -b karthik-feature master
git push -u origin karthik-feature

The -u option adds an upstream tracking reference to your local branch, meaning that you can run push subsequent commits using git push without having to specify the remote and branch names (and run git pull without additional arguments).

git push 
git pull-request 

Why pull requests?

Pull requests are an excellent tool for fostering code review. If you’re using Github for team projects, you should be using these extensively.

Advice for pull requests

Many people don’t realize that you can make pull requests between two branches of the same repository (“shared repository model”).

Advice for pull requests

A good practice is for someone else to merge your code into master, ensuring two sets of eyeballs review each feature. 

 

In larger teams, assign someone who is capable of reviewing. This can be also be an end user.

Advice for pull requests

You can also email the pull-request link to your group/mailing list

hub compare master..<feature_branch>
<more commits>; git push
merge pull request [branch master]

⛔️ Never send a pull request from master 🙅

⛔️ Never send a large pull request without notice 🙅

Forking workflow

Collaborator 2

Main project repository

Fork

Fork

Pull request

Pull request

Collaborator 1

Forking workflow

Everyone has a fork of a "central" repository

Add commits to feature branches

Send pull-request from feature branch to central repository

Tip #1:  Always git pull before you start new work

 

Tip #2:  Keep branch names descriptive

 

Tip #3:  Generously use branches

 

But delete when done

Tip #4:  Use hub command line to simplify your workflow

 

hub.github.com

GitHub Flow