How do I merge any concurrent changes from master into my branch without changing master?
I am really confused with merge
or rebase
.
In master, at point A , I created a branch mybranch
, checkout and started working on it, while others continue to work on master
.
Some time has passed. Today I found that I had master
reached point B , and I still have not finished part in mybranch
.
However, I would like to have all the changes master
have up to B , but I do NOT want to add any of my code to mybranch
in master
.
Then I did
- check master
-
git rebase mybranch
Yes, it mybranch
has all the changes from master between A and B , but I found that it master
also has the changes I made to mybranch
.
It seems now master
and mybranch
now are identical.
I thought it was rebase target
meant to put the current location in target
i.e. just rebase mybranch
based on master
, but why was it two way?
How exactly can I achieve my original goal?
source to share
To achieve your original goal, you need to swap the branches.
git checkout mybranch
git rebase master
Something that acts the same as:
git rebase master mybranch
This means that your mybranch will be added to the master, leaving the master unchanged.
Usually rebase
never affects the target branch. You can do something else.
Alternatively, you can use merge
:
git checkout mybranch
git merge master
This will create a merge commit on mybranch and is a perfectly viable option.
source to share