首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >远程分支未显示在"git分支-r“中

远程分支未显示在"git分支-r“中
EN

Stack Overflow用户
提问于 2012-09-07 22:20:45
回答 5查看 149.5K关注 0票数 166

我一直在推送到远程Bitbucket存储库,最近一位同事将他创建的一个新分支推送到同一存储库。

我在试着获取他上传的更改。

代码语言:javascript
复制
 $ git branch -a
 * master
 localbranch1
 localbranch2
 remotes/origin/master

$ git分支-r源站/主站

在Bitbucket的web UI中,我可以看到他创建的分支。我该怎么做呢?

下一次尝试:

代码语言:javascript
复制
$ git fetch bitbucket
Password for 'https://xxxxx@bitbucket.org':
From https://bitbucket.org/user/repo
 * branch            HEAD       -> FETCH_HEAD

如果他创建的分支名为new_branch_b,我应该看到以下内容吗?

代码语言:javascript
复制
$ git branch -r
origin/master
origin/new_branch_b

第三次尝试:

代码语言:javascript
复制
$ 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

第四次尝试:

代码语言:javascript
复制
[remote "bitbucket"]
url = https://user@bitbucket.org/user/repo.git

我调用了远程bitbucket而不是源(至少我记得是这样的;我在一段时间之前设置了它)

第五次尝试:

我根据kan's answer更新了Bitbucket远程配置

$ git配置-e

代码语言:javascript
复制
[remote "bitbucket"]
    url = https://user@bitbucket.org/user/repo.git
    fetch = +refs/heads/*:refs/remotes/bitbucket/*

对于大多数人来说,它将被称为origin:

代码语言:javascript
复制
[remote "origin"]
    url = https://user@bitbucket.org/user/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

之后,

代码语言:javascript
复制
$ 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

……诸若此类。

我认为git remote update也可以使用git fetch origin

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2012-09-07 23:17:10

remote部分还指定了获取规则。您可以向其中添加类似以下内容的内容,以便从远程获取所有分支:

代码语言:javascript
复制
fetch = +refs/heads/*:refs/remotes/origin/*

(或者用bitbucket替换origin。)

请在这里阅读:

票数 131
EN

Stack Overflow用户

发布于 2012-09-07 22:40:15

如果您仍未更新遥控器,请执行以下操作:

代码语言:javascript
复制
$ git remote update
$ git branch -r
票数 261
EN

Stack Overflow用户

发布于 2017-07-26 17:08:25

如果使用--depth参数进行克隆,它会将.git/config设置为不获取所有分支,而只获取主分支。

您可以简单地省略参数或更新配置文件

代码语言:javascript
复制
fetch = +refs/heads/master:refs/remotes/origin/master

代码语言:javascript
复制
fetch = +refs/heads/*:refs/remotes/origin/*
票数 55
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12319968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档