Useful Git Merging Workflow

This is a useful git workflow for merging development work into the master branch in git that has made for nice clean merges. Special thanks to my Coworker Jeremy for sharing this.

This assumes you’ve cloned to branch “master”, and are working in local branch “dev”. As a best practice, you never really want to work in master, it should always be a clean copy of the remote origin.

From the top, on “master”:

  1. git checkout -b dev
  2. do some dev work
  3. git commit
  4. repeat from 2. until you're ready to commit to the remote

  1. git checkout master
  2. git pull
  3. git checkout dev
  4. git rebase master
  5. git checkout master
  6. git merge dev
  7. git push
  8. git checkout dev
  9. continue from 2

From his original email on this subject: “The other nice thing about this method is that you can have as many “dev” branches as you want and they wont conflict with each other as long as you only ever track to and from master. You can also make child branches from “dev” following the same rebase->merge pattern without any problems.”