How to Squash All Git Commits into One

2021/01/112 min read
bookmark this
Responsive image

Table of Contents

  1. Introduction
  2. Squash Commits with Soft Reset
  3. Conclusion

Introduction

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

A scenario would be that you've been checking in lots of commits to your own local branch, and when you're ready to push them to the origin branch, you don't want to check in so many commits. For example, depending on the developer, you might have 100 commits.

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

Squash Commits with Soft Reset

First, make sure you are on 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 commits should become one. You just need to commit that change.

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

Conclusion

Using git reset --soft is a simple and effective way to squash all local commits into a single commit before pushing to the remote branch.