Quick git tip: Push only some commits to your upstream repo

git status says:

$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.

You want to git push only one of those commits to the public repo. Here’s how:

First use git log to get the commit hash of the commit you want to push. Then:

$ git push origin <thelonghash>:master

(Thanks to ajax).

Update

You can’t push arbitrary commits this way. See Stefan’s comment below.

About these ads

3 Comments

Filed under Uncategorized

3 Responses to Quick git tip: Push only some commits to your upstream repo

  1. Great tip! I love learning something(s) new every day — one of the best things about being involved with you genius types in Fedora, if you ask me.

  2. Stefan Näwe

    One should say that only the commits _up to_ the given one
    are pushed to the other repo.
    It’s not like pushing only one commit, e.g.
    if you have commits A->B->C->D and do ‘git push otherrepo C:master’ the commits A,B, and C will be pushed to otherrepo
    (if they aren’t already there).

    Stefan

  3. rich

    Stefan, this is a very good point.

    The solution would be to use git rebase -i to
    rearrange the commits so that ‘C’ is earliest.

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 )

Connecting to %s