Skip to content

Instantly share code, notes, and snippets.

@stefbowerman
Last active November 4, 2015 22:35
Show Gist options
  • Select an option

  • Save stefbowerman/44946669dbc6bef0f02c to your computer and use it in GitHub Desktop.

Select an option

Save stefbowerman/44946669dbc6bef0f02c to your computer and use it in GitHub Desktop.
How to update master with development branch while keeping the commit history clean

First create an integration branch out of your development branch

git checkout -b myfeature-int

  • This guarantees that you won't spoil your development branch
  • This is especially valid for dev branches that are also remote, we should never rewrite the history of a shared branch

Then rebase that new branch onto master

git rebase -i master myfeature-int

  • Ideally you do an interactive rebase with the -i flag, so that you can squash, reorder, or drop commits
  • Having 3 commits for subsequently renaming a class is an ideal candidate for squashing
  • Don't hesitate to re-do it several times over. It's easier to, for example, first reorder some commits, make sure they can be re-applied in that order, then do a second rebase to squash'em.

Publish that integration branch, so this can be used for reviews

git push -u origin myfeature-int

  • Now all your commits are stacked on top of the latest master, therefore merging to master should be a fast-forward. We want to enforce this.
  • git checkout master
  • git merge myfeature-int --ff-only
  • This will reject non fast-forward merges

Finally if you have to pull again from master before pushing, don't forget to do a pull rebase.

  • git pull --rebase

Delete your integration branch

  • git branch -d myfeature-int
  • If you pushed it, then delete the remote branch too: git push origin --delete myfeature-int

Stolen from https://wiki.magnolia-cms.com/display/DEV/Git%3A+merging+a+development+branch+into+master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment