GIT- Merging, Re-basing, Squashing

Kavit (zenwraight)
2 min readJan 16, 2020

--

Merging, Re-basing and squashing your commits, these are few terminologies used by every Software Developer 3 times a day on an average.

Not Properly using these terms, has landed me in trouble many times.

So here I am sharing few practices that has helped me in keeping my workspace clean and up-to date with master branch.

First and important rule when using git is to always work on child branch, coming out of master or some other branch. If you like to work on master branch, then avoid pushing incomplete changes to remote master branch. Trust me it will save you from a lot of trouble.

Now coming back to our main topic, let’s consider that I have created a working branch called- example-branch-007 .

Problem Statement:- I want to keep my working branch up-to date with master.

  1. git checkout master.
  2. git pull
  3. git checkout example-branch-007.
  4. git merge master .

Clean and less hassle method to keep your current branch up-to date with master.

Now let’s take a look an easy method to squash all your working branch commits into master and push out master.

  1. git checkout master.
  2. git pull
  3. git merge --squash example-branch-007
  4. git commit -m “<custom message>”
  5. git push origin master.

This was a short and quick article on few git tricks to make your day to day job life easy.

--

--

Kavit (zenwraight)
Kavit (zenwraight)

No responses yet