Skip to content

Instantly share code, notes, and snippets.

@dfa1
Last active March 21, 2020 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfa1/8efa3ce530e02f719602e95ae4ef68f3 to your computer and use it in GitHub Desktop.
Save dfa1/8efa3ce530e02f719602e95ae4ef68f3 to your computer and use it in GitHub Desktop.
inattentively squash all commits of a topic branch (i.e. no need to open an editor as in rebase -i)
#!/bin/bash
set -euo pipefail
target_branch=$1
current_branch=$(git rev-parse --abbrev-ref head)
squash_branch=${current_branch}_work
git checkout -B ${squash_branch} ${target_branch}
git merge --squash ${current_branch}
git commit -am "squashed"
git checkout ${current_branch}
git reset --hard ${squash_branch}
git branch -D ${squash_branch}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment