How to rebase feature branch with master branch in Git repository


In this post we will discuss how to rebase feature branch with master branch in Git repository. We have seen post on Git tutorial using command line tool. We will also tell you here using command line tool how to rebase feature branch with master branch in Git repository.

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 and merge command.

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 to use 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 to use 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.

Performing Git Rebase

Here are in general few steps which will tell you how to perform rebase using command line tool.

  1. Navigate to the root directory of your project where you want to perform rebase.
  2. 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.
  3. If conflict occurs, manually resolve them in each file.
  4. Execute command git rebase --continue to continue rebase. You will also get the similar message on console window to perform the same thing.
  5. If conflicts occur again follow steps 3 & 4, otherwise execute git pull from your feature branch if there is any difference.
  6. Commit the code to repository for feature branch.

Thanks for reading.

Related posts

Leave a Comment