Skip to main content

git branching

How to Update a Feature Branch with a Rebase to Include the Latest Master Changes

To update a feature branch with the current state of the master branch using a rebase, follow these steps:

  1. Ensure you are on your feature branch:

    git checkout feature-branch-name
  2. Fetch the latest state of the master branch from the remote repository:

    git fetch origin
  3. Rebase your feature branch onto the latest master:

    git rebase origin/master

    This command applies the changes from your feature branch onto the latest master. If there are conflicts during the rebase, you will need to resolve them manually.

  4. Resolve conflicts manually (if any): After resolving a conflict, mark the file as resolved:

    git add <conflicted-file>

    Continue the rebase:

    git rebase --continue
  5. Push the updated feature branch to the remote repository: If the feature branch was already pushed to the remote repository, you will need to force-push it to overwrite the previous history:

    git push -f

    Note: Be cautious when using git push -f (force push). Ensure no one else has made changes to the feature branch on the remote to avoid overwriting their work.


Summary of Commands:

git checkout feature-branch-name
git fetch origin
git rebase origin/master
# If there are conflicts:
git add <conflicted-file>
git rebase --continue
# If needed:
git push -f