Git Rebasing Local Branch Rebasing

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Rebasing reapplies a series of commits on top of another commit.

To rebase a branch, checkout the branch and then rebase it on top of another branch.

git checkout topic
git rebase master  # rebase current branch onto master branch

This would cause:

      A---B---C topic
     /
D---E---F---G master

To turn into:

              A'--B'--C' topic
             /
D---E---F---G master

These operations can be combined into a single command that checks out the branch and immediately rebases it:

git rebase master topic   # rebase topic branch onto master branch

Important: After the rebase, the applied commits will have a different hash. You should not rebase commits you have already pushed to a remote host. A consequence may be an inability to git push your local rebased branch to a remote host, leaving your only option to git push --force.



Got any Git Question?