Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
692 views
in Technique[技术] by (71.8m points)

version control - Git repository lost its remote branches?

I have a git repository that has a remote set up ("git fetch" works), but it doesn't have any remote branches: the ".git/refs/remotes" folder doesn't exist, and

git branch -r 

returns nothing (empty list, no branches). Yet the actual remote repository does have a branch. If I re-clone the remote repo, I get another local repo that does have remote branches.

I didn't think this state was possible. My questions:

  1. How on earth did I get into this state?
  2. Is there a command that can be run to put ".git/refs/remotes" back? (short of a fresh clone, which I've done already).

Additional Information

"git config --get remote.origin.fetch" is blank (i.e. the command produces no output)

"git remote show origin" shows

$ git remote show origin
* remote origin
  Fetch URL: <correct remote url here>
  Push  URL: <correct remote url here>
  HEAD branch: master
  Local ref configured for 'git push':
    master pushes to master (up to date)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

[Edit, April 2017] If you made your original clone with --single-branch, your remote.origin.fetch setting will be the problem. If you used a --depth limit, that too implies --single-branch. Restore the normal remote.origin.fetch value described below and you will get a fuller clone.


Normally, just running git fetch should restore your remote-tracking branches.

If git fetch is not restoring them, then I wonder: what goes git config --get-all remote.origin.fetch print? (This assumes the remote is named origin; if not, substitute the actual name.) It should be set to +refs/heads/*:refs/remotes/origin/* (again assuming the name origin). Special cases (such as fetching notes) might add more lines.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...