How to Squash All Git Commits into One

2021/1/111 min read
bookmark this
Responsive image

A quick note to show how to squash all git local commits into one. 

A scenario will be, you've been check-in in lots of commits into your own local branch when you ready to push them to the origin branch. You don't want to check-in so many commits, e.g. depending on the developer, you might have 100 commits.

Here is a quick note for doing that in the command line.

First, make sure you are in the correct branch. 

git checkout YourBranch

Then, use the soft reset to the origin branch.

git reset --soft origin/YourBranch

Now, at this moment, all your commit should become one, you just need to check-in that commit.

If you use Visual Studio 2019, it already has a feature that you can squash all local commits to one, however, if you still use Visual Studio 2015, you will have to do that in the command line.