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

  1. commit all your files.
  2. git checkout master
  3. git pull origin master
  4. git checkout your_branch
  5. git rebase master

Squash your X commits.

  1. git rebase -i head~X (where x is no.of commits)
  2. a file will be opened in terminal edit that file.
  3. replace pick with f of all the commits except the first one.
  4. save that file.
  5. your all commits will be squashed to the first one.

Rename your last commit.

  1. git rebase -i HEAD~1
  2. replace pick with r
  3. save the file and a new file will be opened then update the name of that commit.