Git rebase –merge with only some of the commits

I did a few commits, say commit A, B, C
Now I want to push only commit A and B to the remote repo. (And keep commit C to be merged and pushed at a later time)
Before I push, I need to run:

git fetch origin master
git rebase --merge FETCH_HEAD

problem is the above commands will ask me to resolve conflicts of commit C as well, which I’m not planning to push now.

  • Push sub-repo content together (not using git submodules)
  • How can one dry run a git push to check whether one has write permissions to a remote?
  • Merge Pull Request Manually
  • 'git push heroku master' is still asking for authentication
  • Recover files after bad git reset --hard command
  • Remove a specific commit but keep all the commits afterward
  • Is it possible to do the rebase without having to deal with commit C.


  • git alternatives to “svn info” that can be included in a build for traceability?
  • Git force push tag when the tag already exists on remote
  • hudson.plugins.git.GitSCM.determineRevisionToBuild
  • Imposing a Partial Ordering on Git Commit IDs
  • How does git detect that a file has been modified?
  • Can I use git to remove a file somebody else put in the repository that I never use?
  • 2 Solutions collect form web for “Git rebase –merge with only some of the commits”

    Saving before the rebase

    The easiest way to save the commit so you can postpone dealing with the conflicts would be to tag it so you have a reference to the commit later:

    $ git tag save-commitC <sha1>

    Rebasing without commit C

    After you’ve saved a reference, rebase without the commit:

    $ git rebase --interactive --merge FETCH_HEAD

    It should open your editor to file looking like this:

    pick <sha1> <message>
    pick <sha1> <message>
    pick <sha1> <message>

    To delete commit C from this branch’s history, simply remove or comment out the commit’s pick <sha1> <message> line.

    Note that commits are listed in reverse order, with the oldest commits first, the most recent ones last. The first commit on the list should be the first commit that is not an ancestor of FETCH_HEAD.

    Once you’ve rebased without C, go ahead and push:

    $ git push origin master

    Reapplying the commit

    When you’re ready to apply it on the rebased branch:

    $ git cherry-pick save-commitC
       # resolve merge conflicts
    $ git commit
    $ git tag -d save-commitC

    You could reset to commit b, then stash your changes, push, and then reapply your stash.

    git reset HEAD~1
    git stash
    (rebasing or whatever other intermediate steps required go here)
    git push
    git stash pop
    Git Baby is a git and github fan, let's start git clone.