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.
Try this (assuming you’re working with
master branch and your remote is called
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
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^ refers to the first parent of that commit,
HEAD^2 – to its second parent, etc.
Answered By – KL-7