Skip to content

3.Git rebase

JOHNYBASHA SHAIK edited this page Aug 6, 2024 · 1 revision

Git rebase is a powerful tool used to integrate changes from one branch into another. When you rebase your feature branch onto the master branch, you are essentially bringing the latest changes from the master into your feature branch while maintaining a linear project history. Here's a step-by-step guide to rebase your feature branch onto master:

  1. Ensure Your Branch is Up to Date: Before starting the rebase process, make sure your feature branch is up to date with the latest changes from the remote repository by running git fetch and git pull origin master while you are on your local feature branch.

  2. Checkout the Target Branch: Switch to the branch you want to rebase onto. In this case, it's usually the master branch. You can do this by running git checkout master.

  3. Pull the Latest Changes: Pull the latest changes from the remote master branch to ensure that you have all the latest updates. You can do this using git pull origin master.

  4. Rebase Your Feature Branch: After ensuring that the master branch is up to date, switch back to your feature branch using git checkout <feature-branch-name>. Then, perform the rebase using the command git rebase master.

  5. Resolve Any Conflicts: Git may halt the rebase process if it encounters conflicts between your changes and the changes in the master branch. If this happens, Git will prompt you to resolve these conflicts manually. After resolving the conflicts, you need to continue the rebase process by running git rebase --continue.

  6. Push the Rebased Changes: Once the rebase is complete, push the changes to the remote repository using git push origin <feature-branch-name> --force.

It's important to note that the --force flag is used when pushing rebased changes to the remote repository, as the commit history has been rewritten. Be cautious when using --force as it can overwrite changes on the remote repository.

Remember that rebasing rewrites the commit history, so it's essential to communicate with your team before rebasing shared branches.

Clone this wiki locally