newkid101 newkid101 - 1 month ago 8
Git Question

Which branch to push to after git rebase

In my workflow I have

master
and a remote branch
branch1
. I branched out from
branch1
and created
branch2
. I did my work in
branch2
and
branch1
carried on having more things commited by other devs. Once I was done I commited my changes to
branch2
rebased my changes on top of
branch1
's latest commit. Git log in
branch2
shows my commit on top of
branch1
's latest commit so all looks good there. However in
branch1
's
git log
my commits are not seen. Do I have to do a
git push
after I do a
git rebase
? If yes, then In this case, do I push to
branch1
or
branch2
??

Answer

Your changes are not reflected in branch1 because they are not part of branch1.

In your case, branch2 comes after branch1, so you see both. But branch1 is therefore before branch2. From branch1's perspective, branch2 hasn't happened yet.

What you are seeing is correct. If you are using the master branch as your "live" or "final" branch, you could merge branch2 into master:

git checkout master && git merge branch2

This would bring your changes from both branches into master.


Also: The fact that branch1 is remote and branch2 is local doesn't really matter in this case. The commits themselves are in both places (because git is distributed). The "branches" are just names given to different commits to make it easy to manage them.