git push: Push all commits except the last one

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.


A more general approach that works to push up to a certain commit, is to specify the commit hash.

git push <remote> <commit hash>:<branch>

For example, if you have these commits:
111111 <-- first commit
222222
333333
444444
555555
666666 <-- last commit

git push origin 555555:master

..Will push all but your last commit to your remote master branch, and

git push origin 333333:myOtherBranch  

..Will push commits up to and including 333333 to your remote branch myOtherBranch


Another possibility is to

git reset --soft HEAD^

to uncommit your most recent commit and move the changes to staged. Then you can

git push

and it will only push the remaining commits. This way you can see what will be pushed (via git log) before pushing.