My Git Workflow

Posted by on April 17, 2013

TLDR;

  • Keep
    1
    
    master
    shippable
  • Develop on a branch
  • Rebase only on a branch other than master
  • Merge development branch back to master
  • Use
    1
    
    git fetch
    and
    1
    
    git merge origin master
    over
    1
    
    git pull
  • Do a dry run before pushing to master:
    1
    
    git push --dry-run origin master

Details

Develop on a branch

1
2
3
- On master: `git co -b new_branch`
- (will be switched to new_branch)
- Develop, commit, rebase as needed

Staying up to date

As new changes are committed to master, get them from the server and bring those into the branch before merging back into master.

1
2
3
4
5
- Switch to master `git co master`
(note, the next 3 steps (with the exception of the 2nd) are the same as "git pull")
- `git fetch`
- review newly downloaded changes `git log origin/master`
- merge into master `git merge origin/master`

Getting changes onto the branch

To get the new change into new_branch:

1
2
- Switch to new_branch `git co new_branch`
- `git rebase master`

A breakdown of what rebase does:

  • The commits I’ve made to
    1
    
    new_branch
    are “lifted” or “stashed” off of the branch
  • A
    1
    
    git merge master
    is performed
  • My “lifted” commits are then reapplied

*Note:* If there are conflicts, I am prompted to fix them at this point, on the branch

Work is complete

When I am ready to merge all work done on

1
new_branch
back into master I simply do:

1
2
- From new_branch: git co master 
- On master: git merge new_branch

Measure twice, cut once

At this point, before pushing code to origin, I do a “dry run” to verify I have the latest changes from master after my last fetch

1
git push --dry-run origin master

Then if all is clean:

1
git push origin master