Skip to content

Instantly share code, notes, and snippets.

@n00neimp0rtant
Last active September 5, 2024 09:24
Show Gist options
  • Save n00neimp0rtant/9515611 to your computer and use it in GitHub Desktop.
Save n00neimp0rtant/9515611 to your computer and use it in GitHub Desktop.
simple squash without rebase
## within current branch, squashes all commits that are ahead of master down into one
## useful if you merged with upstream in the middle of your commits (rebase could get very ugly if this is the case)
## commit any working changes on branch "mybranchname", then...
git checkout master
git checkout -b mybranchname_temp
git merge --squash mybranchname
git commit -am "Message describing all squashed commits"
git branch -m mybranchname mybranchname_unsquashed
git branch -m mybranchname
## optional, not recommended if you want to keep the unsquashed history around for a bit longer
git branch -D mybranchname_unsquashed
## if squashing already-pushed commits...
git push --force
@shahi645
Copy link

Cheers again bro!

@sgupta-paymerang
Copy link

Thanks a lot !! You saved my time :)

@shahi645
Copy link

Once again this has served me well...thanks!

@shahi645
Copy link

Fair play, this has once again pulled me from the darkness

@shahi645
Copy link

shahi645 commented Oct 8, 2018

Nice one m8!

@dbcoderain
Copy link

Brilliant, thanks for this

@chengwhynot
Copy link

cool

@HelloBanksy
Copy link

Note that you might face the issue of setting tracking information as well (connecting your new squashed branch to your remote one). To handle this you will need to do:
git branch --set-upstream-to=origin/myfeaturebranch myfeaturebranch

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