Git remote branch not showing, so I cannot merge

2019-09-16 17:51发布

问题:

I tried to merge with a remote branch and I am having problems.

My git remote network looks like this:

https://github.com/liuduan/CAT-APP-PROJECT/network

>> git branch -r
SS-Master/master
origin/Department_Head
origin/HEAD -> origin/master
origin/HEAD_2
origin/President
origin/master

It did not show the branch for "master/ashimaSharma". How do I have git to show the "master/ashimaSharma" branch?

Then I tried:

>>git fetch –-all
Fetching origin
Fetching SS-Master

>>Fetching HEAD_2
remote: Not Found
fatal: repository 'https://github.com/liuduan/CAT-APP-PROJECT/commit/d54b6f1db7ff624970105fdfe5c0a1aa60a9d7b2/' not found
error: Could not fetch HEAD_2

Actually I do not really care about HEAD_2 branch, but I need to show the branch "master/ashimaSharma", so I can merge.

I got a suggestion from max630 to remove HEAD_2, and I removed it successfully.

I did ”get fetch –-all”, and ”get remote -v”,

git remote -v
SS-Master       https://github.com/sumit0704/CAT-APP-PROJECT/ (fetch)
SS-Master       https://github.com/sumit0704/CAT-APP-PROJECT/ (push)
origin  https://github.com/liuduan/CAT-APP-PROJECT (fetch)
origin  https://github.com/liuduan/CAT-APP-PROJECT (push)

But the “master/ashimaSharma” is still not showing up.

回答1:

You have remote named "HEAD_2", pointing to some nonexistent URL. You should remove it.

git for-each-ref 'refs/remotes/HEAD_2/' # ***verify that it's empty, so that you don't delete anything important***
git remote remove HEAD_2

PS: Then you should add the ashima1491's fork as another remote:

git remote add ashima1491 https://github.com/ashima1491/CAT-APP-PROJECT


回答2:

Answered here.

Remote branch won't show any work done in the forked repositories. In your case the remote branches are Department_Head, HEAD_2, President and master. If you really want to merge "ashima1491"'s changes, ask him to send you a pull request.

Alternatively - You can also add another "remote" (the other github repository) by using
git remote add origin1 https://github.com/ashima1491/CAT-APP-PROJECT.git
This will add another remote named "origin1" which points to ashima1491's github repository. Next you can pull her code to your repository using -
git pull origin1 master
given you are currently at your master branch this will "pull" her master branch to your master. You can then add, commit and push.