Take the 2-minute tour ×

Is there a way to push all my local commits to the remote repository except the most recent one? I'd like to keep the last one locally just in case I need to do an amend. Thanks.

share|improve this question
add comment

1 Answer

up vote 13 down vote accepted

Try this (assuming you're working with master branch and your remote is called origin):

git push origin HEAD^:master

HEAD^ points to the commit before the last one in the current branch (the last commit can be referred as HEAD) so this command pushes this commit (with all previous commits) to remote origin/master branch.

In case you're interested you can find more information about specifying revisions in this man page.

Update: I doubt that's the case, but anyway, you should be careful with that command if your last commit is merge. With merge commit in the HEAD HEAD^ refers to the first parent of that commit, HEAD^2 - to its second parent, etc.

share|improve this answer
add comment

Your Answer


