Git-Squashing Multiple Commit into a single one

Nilisha Jaiswal
1 min readFeb 19, 2021

A tool which comes into handy when we want to group together several small commits into a single lump to push upstream.

Steps to follow:

1.Firstly invoke git and move to the required branch.

2.Type the following command in the terminal and press enter:

git rebase -i HEAD~N

where N is the number of commits you want to join.(However, if you need the full list of commits you can run git log command)

3.Now you will be shown the list of commits(in reverse order with older commits on the top) you want to merge.

4.Mark the commit as squashable by changing the word pick into s

(Note-Mark all commit which you want to combine, as squashable except the first one as it will be used as the starting point.)

5.Now save the file(If using VS code terminal use :wq).The rebase process will start and during the process it will open an editor which has commit messages of all the commits you want to combine.

6.You now can create a new commit message for the squashed commit.

7.Lastly, do the git push.

And Viola you are done!!

Leave a clap if you found it helpful :)

--

--