Skip to content

Instantly share code, notes, and snippets.

@Slava
Created May 9, 2013 19:36
Show Gist options
  • Save Slava/5549976 to your computer and use it in GitHub Desktop.
Save Slava/5549976 to your computer and use it in GitHub Desktop.
[how-to][git] Merge my branch to `devel` branch

Merge my branch to devel

Let's say I have branch send-stats, and I have couple of commits which I need to squash and merge to devel branch.

Follow these steps:

  • git checkout send-stats - switch to my branch
  • git rebase -i devel - rebase interactively relatively to devel, here we need to squash all commits to the first one
    • in vim: :2,$s/pick/f/ - relaces picks to f for every line except first one - indicates those commits as 'to squash'
    • save
  • git push -f upstream - push upstream to origin, changing history
  • git checkout devel - switch to devel
  • git pull - what if origin/devel changed? pull it!
  • git checkout send-stats - back to my branch (this awkward moment you jump between branches for no good reason)
  • git rebase origin/devel - put newly squashed commit on top of devel branch
  • git push -f - not sure if we need it, but let's rewrite the history once again
  • git checkout devel - I know, back there
  • git merge send-stats - finally!
  • git push - uhhh, it was a long day
  • git push origin :send-stats - that's how we delete the branch in git :(
  • drink coke

In case of commiting all commits with history make sure you get extra commit of merging meaning there is no fast-forward: use key --no-ff

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