我一直在将代码推送到远程的Bitbucket仓库,最近一位同事也向这个仓库推送了一个新分支。
我正在尝试获取他上传的更改。
$ git branch -a
* master
localbranch1
localbranch2
remotes/origin/master
$ git branch -r origin/master
在 Bitbucket 的 web UI 中我可以看到他创建的分支,我该如何做到这一点?
接下来尝试:
$ git fetch bitbucket
Password for 'https://xxxxx@bitbucket.org':
From https://bitbucket.org/user/repo
* branch HEAD -> FETCH_HEAD
如果他创建的分支叫做new_branch_b,那么我应该期待看到以下内容吗?
$ git branch -r
origin/master
origin/new_branch_b
第三次尝试:
$ 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
第四次尝试:
[remote "bitbucket"]
url = https://user@bitbucket.org/user/repo.git
我调用了远程的bitbucket
而不是origin(至少我记得是这样; 我设置它已经有一段时间了)
第五次尝试:
我按照kan的答案更新了Bitbucket远程配置:
$ git config -e
[remote "bitbucket"]
url = https://user@bitbucket.org/user/repo.git
fetch = +refs/heads/*:refs/remotes/bitbucket/*
对于大多数人来说,它将被称为"origin":
[remote "origin"]
url = https://user@bitbucket.org/user/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
之后,
$ 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 fetch origin
也可以用于 git remote update
。
refs/remotes/bitbucket/*
而不是refs/remotes/origin/*
更有意义。 - kangit fetch origin
完成了这项工作。 - coretechie