Skip to content

Instantly share code, notes, and snippets.

@xcambar
Created February 17, 2015 09:49
Show Gist options
  • Save xcambar/3f520db33c45e567fdd9 to your computer and use it in GitHub Desktop.
Save xcambar/3f520db33c45e567fdd9 to your computer and use it in GitHub Desktop.
A Shell script to make git squashing a bit more straightforward
# gqs <-> git quick squash
#
# Rebases from the branch passed in argument
# Squashes the commits on top of it
#
# example: gqs origin/master
#
function gqs () {
local branch=$1
git fetch > /dev/null
git rebase $branch > /dev/null
local number_of_commits=`git log $branch..HEAD --pretty=oneline | wc -l | xargs`
if [ $number_of_commits -gt 0 ]; then
echo "squashing $number_of_commits commits"
git rebase -i HEAD~$number_of_commits
else
echo "Nothing to squash"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment