简体   繁体   English

远程分支没有出现在“git branch -r”中

[英]Remote branch is not showing up in “git branch -r”

I have been pushing to a remote Bitbucket repository and recently a colleague has pushed a new branch he created to the same repository.我一直在推送到远程 Bitbucket 存储库,最近一位同事将他创建的新分支推送到同一个存储库。

I'm trying to fetch the changes he uploaded.我正在尝试获取他上传的更改。

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

$ git branch -r origin/master $ git branch -r origin/master

In the web UI for Bitbucket I can see the branch he has made.在 Bitbucket 的 Web UI 中,我可以看到他创建的分支。 How can I do this?我怎样才能做到这一点?

Next try:下一次尝试:

$ 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 the following?如果他创建的分支名为new_branch_b ,我应该期待看到以下内容吗?

$ git branch -r
origin/master
origin/new_branch_b

Third try:第三次尝试:

$ 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

Fourth try:第四次尝试:

[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)我调用了远程bitbucket而不是 origin(至少我记得是这样;我不久前设置了它)

Fifth try:第五次尝试:

I updated the Bitbucket remote configuration as per kan's answer :我根据kan 的回答更新了 Bitbucket 远程配置:

$ git config -e $ git 配置 -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 .我认为git fetch origin也适用于git remote update

Update your remote if you still haven't done so:如果您还没有这样做,请更新您的遥控器:

$ git remote update
$ git branch -r

The remote section also specifies fetch rules. remote部分还指定了获取规则。 You could add something like this into it to fetch all branches from the remote:您可以在其中添加类似的内容以从远程获取所有分支:

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

(Or replace origin with bitbucket .) (或者用bitbucket替换origin 。)

Please read about it here: 10.5 Git Internals - The Refspec请在此处阅读: 10.5 Git Internals - The Refspec

If you clone with the --depth parameter, it sets .git/config not to fetch all branches, but only master.如果使用--depth参数进行克隆,它会将.git/config不获取所有分支,而只获取 master。

You can simply omit the parameter or update the configuration file from您可以简单地省略参数或更新配置文件

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

to

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

I had the same issue.我遇到过同样的问题。 It seems the easiest solution is to just remove the remote, readd it, and fetch.似乎最简单的解决方案是删除遥控器,读取它并获取。

Unfortunately, git branch -a and git branch -r do not show you all remote branches, if you haven't executed a "git fetch".不幸的是,如果您没有执行“git fetch”, git branch -agit branch -r不会向您显示所有远程分支。

git remote show origin works consistently all the time. git remote show origin始终如一git remote show origin工作。 Also git show-ref shows all references in the Git repository.此外git show-ref显示 Git 存储库中的所有引用。 However, it works just like the git branch command.然而,它就像git branch命令一样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM