0

I have a commit C1 in master. I have branched out after that and have made commit C2 in branch. Now I want to push only commit C2 to master.(C1 is not yet ready to be pushed) How to do that..

    C2(branch)
  /
|
|
C1 (master)

Thanks..

Exuberant
  • 189
  • 2
  • 13

2 Answers2

0

you can use git cherry-pick and specify the commit ids that you want to merge

git cherry-pick C2 

will merge only commit C2 into the master branch

BartBog
  • 1,889
  • 14
  • 28
Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
0

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
eckes
  • 64,417
  • 29
  • 168
  • 201