That message means that your local repo has diverged from the GitHub remote repo; that is, there are local commits that don't exist remotely, and vice versa.
If you really don't care what's happened to the remote repo, then you can run git push -f
to force the push through, but if there are any other repos (yours or anyone else's) that have already pulled the non-local changes that have somehow ended up on GitHub, then this will really screw things up for them! Any changes on GitHub that you don't have locally will be lost.
If in doubt, commit any local changes, make a note of the current HEAD commit ID (you can use git show
to find it) and then pull down the remote changes, fix any merge conflicts, and push back up. If things go wrong, you can always just git reset --hard <commit-id>
to go back to where you were before. This route doesn't modify history, so there's no danger of losing anything.
Basically you need to be careful in Git with any operation that modifies the commit history of a repo, which push -f
does, since it'll potentially lead to inconsistent histories between repos. On the other hand, if you only append to a repo's history (which is what you should be doing, e.g. with git commit
, git pull
, git merge
, etc.) then if it breaks, you can always get it back into a working state just by rewinding to before the offending commits with git reset
.
Also, you can see the commits on GitHub that you don't have with git log origin/master...master
, or git diff origin/master...master
to see the actual changes (make sure you run git fetch
first).