Git is a useful tool for Version control. Git Rebasing is used when we have a scenario like we are working in a feature branch and not taken the pull within the last 3 days . Also the remote has 3 more commits we don’t have in our feature branch. Also the Feature branch has 5 commits. You need to push the feature branch without loosing the existing commits in master and and feature branch too.
Consider that you have 3 commits in master.From that branch ,create 1 branch named feature_branch . After that your co workers push a commit named 4 to remote .But that commit is not available in feature_branch. Also you have created 2 more commits in your feature branch namely 5 and 6. Now what you need to do is merge commit no 4 to your feature branch . Then only you can able to push your commits to remote .
We have a git command called git merge origin/master is for this purpose. But the problem with this command is that it will create a new commit as merge commit . what you need to get that commit from remote without a merge commit. For that we can use this
Example 1 : using git Merge
create an another branch named test and checkout to that branch
add some more commits to that local branches.
now checkout to master and add a new commit there..
now switch to your local branch and do the command
git merge master
there is an additional merge commit is present along with other commits .Thats can be avoided by using the
Example 1 : using git rebase.
create new branch named rebase_ex and add some commits there.
now the commits in rebase_ex are ..
now checkout to master and the master commits are
now create some new commits there
total commits in master are
now checkout to your feature branch and do the
git rebase master
so the total commits currently in your local branch is
master commits + your feature branch commits too.
Tada.. all done . you are now expert in the git rebase . one thing you need to understand is ; there is no merge commit is now created .