Search code examples
gitgit-push

How to limit which commits get sent when performing git push?


I'd like to push some mature commits to remote, but exclude the most recent commits.

I've read the man page for git-push, but probably don't fully understand how to make use of the <refspec> parameter.

I should probably avoid this situation by creating a separate development branch from which I can do all my clean up (rebase squash/drop/edit/etc.) before bringing chunked commits into a branch that tracks the remote branch. I didn't have the foresight and now I have a bunch of "fragment" commits that I don't want to publish, but I need to push the others.


Solution

  • First, find the ref for the commit you want to push. This can be anything commitish, for instance: 12d3f1, HEAD^, etc.

    Then, do this:

    git push origin <commitish>:<branch>
    

    This means take "commitish" and make the <branch> on origin point to this commit.

    A <branch> is nothing but a pointer to some commit.

    This will fail if the <commitish> commit doesn't have the current remote <branch> in it's history.