Vikash
Vikash

Reputation: 3551

Does rebasing a branch chnage the current branch or the branch which we rebased

I was going through the documentation of git rebase and git merge. I understood the difference and rebasing almost, but i have one doubt. Does rebase effect the current branch or the rebased branch.

For Example:

I have a branch new-branch checked out from master and both master and new-checkout branch progressed, Now after pushing some commits in new-branch, I want to rebase it with origin master.

I ran this command in my-branch

git rebase master

I did the rebasing, I know that git will put some new commits of my-branch on the top of current master branch head.

Now my question is that, if i will force push from the my-branch, then will it change the code of my-branch or it will change the remote master branch.

Hope you understood my question, please let me know if anything is confusing in my question. Any help would be appreciated.

Upvotes: 1

Views: 122

Answers (1)

Marina Liu
Marina Liu

Reputation: 38106

git rebase master will change the commit history on new-branch.

As below graphs, assume the original commit history is:

A---B---C---G---H   master
         \
          D---E---F  my-branch

After executing git rebase master, it will rebase the changes from my-branch to master branch. And the commit history will look like:

A---B---C---G---H---D'---E'---F'   my-branch
                |
              master

If you force push for my-branch to remote (git push -f origin my-branch), the remote my-branch will change the version as F' as above graph.

Upvotes: 2

Related Questions