Skip to content

Instantly share code, notes, and snippets.

@whunter
Last active July 22, 2021 14:03
Show Gist options
  • Save whunter/cd118aad08f6863ca1b559f5c1ed575e to your computer and use it in GitHub Desktop.
Save whunter/cd118aad08f6863ca1b559f5c1ed575e to your computer and use it in GitHub Desktop.
Squash your commits super easily
#!/bin/bash
# Add a "squash" alias that calls this file and then you can squash your commits by running "squash master" (or whichever branch you want to rebase against)
base_branch=$1
if [[ -n "$base_branch" ]]; then
current_branch=`git branch --show-current`;
echo "Squashing $current_branch";
commits=`git log $base_branch..$current_branch --oneline | wc -l | xargs`;
echo "$commits commits";
git rebase --interactive HEAD~"$commits";
else
echo "Usage: squash <base_branch>";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment