Totally stuck in git - "git push" does not work, and "git pull" doesnt' fix
I decided to try to mess around with Git today and try to learn how its branching system works. Bad idea. I somehow have gotten myself in a state where I have committed a change on a branch, and when I do "git push" I get:
To git@github.com:LAW/Repo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:LAW/Repo.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
I've seen this a few times, and I have done "git pull" to resolve, though I'm not sure why or how that resolves things. The problem is, it isn't working now. I do "git pull" and get:
"Already up-to-date."
And the problem persists. So my question is...now what? I can't push from the branch, so it is essentially dead, but the internet has no better advice than "git pull" to fix this. Needless to say this is VERY frustrating!
EDIT A commenter requested the output of "git branch -a". The bran开发者_运维技巧ch in question is "PersonalSite"
* PersonalSite
master
remotes/origin/HEAD -> origin/master
remotes/origin/PersonalSite
remotes/origin/master
Your rejected push is master -> master. But the branch you're on is PersonalSite. It sounds like your master branch has a local commit that remote doesn't, but is missing commits from remote. However, you're trying to git pull
on PersonalSite. I'm not sure what branch it's trying to pull from, probably origin/master
(this depends on the upstream information you may have set up when creating the branch). git push
isn't trying to push PersonalSite since, by default, it only pushes "matching" branches (e.g. branches that already exist on both sides) and PersonalSite only exists locally.
What are you trying to achieve here? If you want to push PersonalSite to remote, use git push origin PersonalSite
. If you want to fix your master branch, check it out and then run your git pull
(or whatever else you want to do to fix it up).
You should be able to simply update the master branch:
git checkout master
git pull
To verify:
git checkout PersonalSite
git push # Should say "Everything up-to-date"
The branch that's being rejected is the master
branch. You're not on the master
branch, you're on PersonalSite
branch, which (as the output from git pull
suggests) is already up-to-date.
git push
with no extra arguments can be configured in different ways (see the push.default
section of git help config
). By default it pushes all matching branches. In this case, it's trying to push master
, but the master
branch is not up-to-date, so the push fails. The error message is a little misleading.
精彩评论