GIT- Merging, Re-basing, Squashing
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.
- git checkout master.
- git pull
- git checkout example-branch-007.
- 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.
- git checkout master.
- git pull
git merge --squash example-branch-007
- git commit -m “<custom message>”
- git push origin master.
This was a short and quick article on few git tricks to make your day to day job life easy.