Git Squash and rebase
Squashing and rebasing the commits is one of the important parts of Github. so here we will see how it works.
rebasing your branch with the master branch. suppose you are in your working branch
- commit all your files.
git checkout master
git pull origin master
git checkout your_branch
git rebase master
Squash your X commits.
git rebase -i head~X
(where x is no.of commits)- a file will be opened in terminal edit that file.
- replace
pick
withf
of all the commits except the first one. - save that file.
- your all commits will be squashed to the first one.
Rename your last commit.
git rebase -i HEAD~1
- replace
pick
withr
- save the file and a new file will be opened then update the name of that commit.