Skip to content

Instantly share code, notes, and snippets.

@jcallin
Last active December 28, 2018 17:09
Show Gist options
  • Save jcallin/6ecaccc63adaa23a7dd51c483d7facca to your computer and use it in GitHub Desktop.
Save jcallin/6ecaccc63adaa23a7dd51c483d7facca to your computer and use it in GitHub Desktop.
Optimal git merge workflow
# We will squash into master, but push the result back to our feature branch. This way we can easily open a PR for the squashed commit.
git checkout branch
# Set HEAD back to origin/master so we can merge to the correct place on remote, but keep local changes to master intact if we have them
git reset --hard origin/master
# Merge our branch to current head (origin/master set from last command). Squash to one commit.
git merge --squash origin/branch
# In the merge commit, include all commits to the branch
git commit --no-edit
# Push the squashed commit on branch so we can open a PR
git push --force-with-lease
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment