Remote branch not showing up in “git branch -r”

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

问题:

I have been pushing to a remote bitbucket repo and recently a colleague has pushed a new branch he created to the same repo.

I'm trying to fetch the changes he uploaded.

 $ git branch -a    * master   localbranch1  localbranch2  remotes/origin/master 

$ git branch -r
origin/master

In the web ui for bitbucket I can see the branch he has made. Any help/advice/direction would be most appreciated. Thanks.

Any futher info you need just ask.

EDIT 1

$ git fetch bitbucket Password for 'https://xxxxx@bitbucket.org': From https://bitbucket.org/user/repo  * branch            HEAD       -> FETCH_HEAD 

If the branch he created is called new_branch_b should I be expecting to see:

$ git branch -r     origin/master  origin/new_branch_b 

EDIT 2

$ git remote update Fetching bitbucket Password for 'https://xxxxx@bitbucket.org': From https://bitbucket.org/user/repo  * branch            HEAD       -> FETCH_HEAD   $ git branch -r   origin/master 

EDIT 3

[remote "bitbucket"] url = https://user@bitbucket.org/user/repo.git 

I called the remote bitbucket rather than origin (at least that's what I recall, I set it up a while ago)

EDIT 4

I updated the bitbucket remote config as per kan's answer.

$ git config -e

[remote "bitbucket"]     url = https://user@bitbucket.org/user/repo.git     fetch = +refs/heads/*:refs/remotes/bitbucket/* 

For most people it will be called origin

[remote "origin"]     url = https://user@bitbucket.org/user/repo.git     fetch = +refs/heads/*:refs/remotes/origin/* 

Afterwards

$ git remote update  Fetching bitbucket Password for 'https://user@bitbucket.org': remote: Counting objects: 48, done. remote: Compressing objects: 100% (32/32), done. remote: Total 35 (delta 21), reused 0 (delta 0) Unpacking objects: 100% (35/35), done. From https://bitbucket.org/user/repo  * [new branch]      branch_name1 -> origin/branch_name1  * [new branch]      branch_name2    -> origin/branch_name2 

.... and so on.

I think git fetch origin would also work for git remote update

Thanks to everyone who helped me with this problem.

回答1:

The remote section specifies also fetch rules. You could add something like into it:

fetch = +refs/heads/*:refs/remotes/origin/* 

to fetch all branches from the remote. (or replace origin by bitbucket).

Please read about it here: https://git-scm.com/book/en/v2/Git-Internals-The-Refspec



回答2:

Update your remote if you still haven't done so:

$ git remote update $ git branch -r 


回答3:

I had the same issue. Seems the easiest solution is to just remove the remote, re-add it, and fetch.



回答4:

If you clone with --depth parameter, it sets .git/config not to fetch all branches, but only master.

You can simple omit the parameter or update config file from

fetch = +refs/heads/master:refs/remotes/origin/master 

to

fetch = +refs/heads/*:refs/remotes/origin/* 


回答5:

Unfortunately git branch -a and git branch -r do NOT show you all remote branches, if you haven't executed a "git fetch". git remote show origin works consistently all the time. Also git show-ref shows all references in the git repo. However it works just like git branch command



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