What you are seeing is a git safety feature. git refuses to update the remote branch with your branch because your branch's head commit is not a direct descendent of the current head commit of the branch that you are pushing to.
If this were not the case, then two people pushing to the same repository at about the same time would not know that there was a new commit coming in at the same time and whoever pushed last would lose the work of the previous pusher without either of them realising this.
If you know that you are the only person pushing and you want to push an amended commit or push a commit that winds back the branch, you can 'force' git to update the remote branch by using the -f switch.
git push -f origin master
Even this may not work as git allows remote repositories to refuse non-fastforward pushes at the far end by using the config variable 'receive.denynonfastforwards'. If this is the case the rejection reason will look like this (note the 'remote rejected' part):
! [remote rejected] master -> master (non-fast forward)
To get around this, you either need to change the remote repository's config or as a dirty hack you can delete and recreate the branch thus:
git push origin :master
git push origin master
In general the last parameter to git push
uses the format <local_ref>:<remote_ref>
, where local_ref
is the name of the branch on the local repository and remote_ref
is the name of the branch on the remote repository. This command pair uses two shorthands. :master
has a null local_ref which means push a null branch to the remote side master
, i.e. delete the remote branch. A branch name with no :
means push the local branch with the given name to the remote branch with the same name. master
in this situation is short for master:master
.