Git: Only push some commits upstream

To me it happens quite frequently that I have several local commits (in a private Git checkout), of which I only want to push some upstream. One option is to use cherry-pick and extra branches. Today I found a more straightforward solution:

git push origin $SHA_OF_LAST_COMMIT:master

Git only pushes the commit specified by it’s hash sum and all it’s ancestors (on the current local branch) that aren’t yet upstream (on the master branch of the origin remote). Finally, git rebase -i can be used to consecutively rearrange the (local) commits you want to push. Much easier, no?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s