First of all, your wording is a bit confusing: when talking about push
, there's always a remote involved. So you don't git push
from branch
to master
but to origin/master
.
If I understood you correctly, here's how to push exactly one commit from your branch branch
to origin/master
Check out a fresh local branch tmp-for-pushing
from your last pushed revision:
git fetch origin && git checkout -b tmp-for-pushing origin/master
Cherry-pick C2
into this branch:
git cherry-pick C2
Publish this single commit:
git push origin tmp-for-pushing:master
By now, you updated your remote but we need to clean up again.
Checkout master again:
git checkout master
Throw away your temporary branch
git branch -D tmp-for-pushing
Rebase master onto your updated origin/master
git fetch origin && git rebase origin/master
Rebase C2 onto your updated master
(if C2
was the only commit there, C2
will equal master
after this:
git checkout branch && git rebase master