git pull displays “fatal: Couldn't find remote ref refs/heads/xxxx” and hangs up

匿名 (未验证) 提交于 2019-12-03 01:14:02

问题:

I created a branch called '6796', then I pushed it to remote, checked it out on another machine, made other edits, pushed it, then merged it with the master, and deleted it - locally and remotely (git push :6796) - on the other machine. Now, when I run git pull:

fatal: Couldn't find remote ref refs/heads/6796 user@host:~/path/to/repo$ fatal: The remote end hung up unexpectedly 

but git pull origin master works normally. It seems to me that there is some 6796 reference hang up... how to resolve this?

回答1:

There are probably some commands to resolve it, but I would start by looking in your .git/config file for references to that branch, and removing them.



回答2:

You also have to delete the local branch:

git branch -d 6796 

Another way is to prune all stale branches from your local repository. This will delete all local branches that already have been removed from the remote:

git remote prune origin --dry-run 


回答3:

I had a similar issue when I tried to get a pull with a single quote ' in it's name.

I had to escape the pull request name:

git pull https://github.com/foo/bar namewithsingle"'"quote 


回答4:

This error could be thrown in the following situation as well.

You want to checkout branch called feature from remote repository but the error is thrown because you already have branch called feature/<feature_name> in your local repository.

Simply checkout the feature branch under a different name:

git checkout -b <new_branch_name> <remote>/feature 


回答5:

I just ran into a similar issue when I tried to commit to a newly created repo with a "." in it's name. I've seen several others have different issues with putting a "." in the repo name.

I just re-created the repo and

replaced "." with "-" 

There may be other ways to resolve this, but this was a quick fix for me since it was a new repo.



回答6:

To pull a remote branch locally, I do the following:

git checkout -b branchname // creates a local branch with the same name and checks out on it

git pull origin branchname // pulls the remote one onto your local one

The only time I did this and it didn't work, I deleted the repo, cloned it again and repeated the above 2 steps; it worked.



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