Reputation: 11
Is it possible to "move" a branch?
For example:
Situation after first git pull
:
A--B--C master
\
D--E--F working
Situation after updating a master
branch:
A--B--C--D--E master
\
M--N--O working
Would be possible now to move my working
branch and getting something like this (to have an updated master
branch with my code that is in working
branch together)?:
A--B--C--D--E master
\
M--N--O working
Upvotes: 1
Views: 194
Reputation: 151
Yes, this can be done through rebasing as @FreshD has replied. Though your work will remain the same, your git history will change.
So you will have something like this in the end.
A--B--C--D--E master
\
M'--N'--O' working
Another way to achieve the same result is through cherry-pick (we make a new branch and cherry-pick our missing commits from the working branch).
git checkout master
git pull
git checkout -b working-copy
git cherry-pick M
git cherry-pick N
git cherry-pick O
(Provided if there are any conflicts we resolve them).
Please also note the full command to the previous answer is
git checkout master && git pull
git checkout working
git rebase master
Upvotes: 3
Reputation: 3112
Yes this can be done with rebasing. First checkout your branch and then rebase to the current master.
git checkout working
git rebase master
Now your branch is based on the current master. If you already have pushed the working branch and want to push again with the rebased version you have to force push. Be careful as this will override the existing origin with the current one, no matter what's there.
Upvotes: 2