git local master branch stopped tracking remotes/origin/master, can't push

喜欢而已 提交于 2019-11-30 19:54:57
Peter Farmer

When you do a git pull did you actually want to do a git push?

For some reason git pull is "pulling" from your current directory, I suspect you want to be pulling from remotes/origin/HEAD.

What output does git push origin produce?

[Addendum by Paul]: This led me to the correct answer, so I'm accepting. The additional steps it took to figure out what was going on were:

# see details of the current config:
$ git config -l
branch.master.remote=. # uh oh, this should point to origin
# to see what it should be ,make a clean clone of the same project 
#   in a different directory, checkout the master branch and run the
#   same command. That showed "branch.master.remote=origin", so...

# then to fix:
$ git config branch.master.remote origin

After that, the local master was tracking remotes/origin/master again. Thanks to Peter Farmer for the clue that got me here!

Paul Smith

Doing some investigation following on from Peter and Nick's comments led to:

# botched local clone:
$ git config -l
branch.master.remote=.
branch.master.merge=refs/heads/master
[...]

# new / clean local clone:
$ git config -l
branch.master.remote=origin
branch.master.merge=refs/heads/master
[...]

Hopefully I can post this as an answer without accepting it (if not I'll have to delete & put it in a comment or the original question). Doing...

$ git config branch.master.remote origin

...got branch.master.remote to =origin again, but it doesn't explain how it got "untracked" in the first place.

If someone can explain cleanly:

a) how my local "botched" repo might have gotten into such a state given the workflow in my question, and

b) the right sequence of actions to get back in sync safely (given that the remote head could have advanced in the meanwhile), I'd like to mark that as the accepted answer, as I think it would be most useful to others in this situation.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!