In this post I will discuss how to rebase feature branch with master branch in Git repository. You might have seen post on Git tutorial using command line tool. I will also tell you here how to use command line tool to rebase feature branch with master branch in Git repository. You can also use any graphical user interface, for example, GitHub, GitLab, Source Tree, Tortoise Git, etc. to do the same operation. Here I am going to tell you only using command line tool (cmd).
In Git, the
rebase command integrates changes from one branch into another. It is an alternative to the
merge command. But there is a difference between
Rebase is one of two Git utilities that specializes in integrating changes from one branch to another. The other change utility is Git merge. Merge is always a forward moving change record. Alternatively, rebase has powerful history rewriting features.
Rebase is generally performed when you need straight, linear or clean history of commits.
Merge does not obliterate your commits. Merge preserves history. Rebase rewrites history, which is a Bad Thing after you’ve pushed it.
Use merge instead of rebase whenever you have already pushed.
When You Need Merge?
- When you have pushed the branch or others team members are working on it too.
- You do not need the full history of activities, i.e., commits.
When You Need Rebase?
- When you have not pushed the branch or no one else is working on it.
- You want the full history of activities, i.e., commits.
- You want to avoid all the auto-generated merged commit messages.
Git Rebase using CMD
Here are, in general, few steps which will tell you how to perform rebase using command line tool.
- Navigate to the root directory of your project where you want to perform rebase.
- Execute command
git fetch && git rebase origin/master. In this case, you have navigated to the feature branch using command line tool to execute the command.
- If conflict occurs, manually resolve them in each file.
- Execute command
git rebase --continueto continue rebase. You will also get the similar message on console window to perform the same thing.
- If conflicts occur again follow steps 3 & 4, otherwise execute
git pullfrom your feature branch if there is any difference.
- Commit the code to repository for feature branch.
That’s all about how to perform rebase using command line tool in Git repository.