我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:
$ git branch
* master
我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?
$ git branch
* master
* staging
* etc...
我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:
$ git branch
* master
我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?
$ git branch
* master
* staging
* etc...
当前回答
|‾‾‾‾‾‾‾‾‾‾‾‾‾fetch/clone‾‾‾‾‾‾‾‾‾‾‾‾↓ |‾‾‾‾‾‾‾‾‾‾‾‾checkout‾‾‾‾‾‾‾‾‾‾↓
|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾pull‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾↓
Remote repository (`origin`) <=> Local repository <=> Index <=> Workspace
↑_________________push_______________| ↑____commit____| ↑____add_____|
# 拉取远程仓库所有分支信息 → 本地仓库
# fetch all remote repository branch meta → local repository
git remote set-branches origin '*'
git fetch -v
# 把所有远程分支数据搞到本地
# fetch all remote repository branch data → local repository
git branch -r | grep -v '\->' | while read remote; do git branch "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
其他回答
Bash for循环不适合我,但这正是我想要的。我的所有分支在本地镜像为相同的名称。
git checkout --detach
git fetch origin '+refs/heads/*:refs/heads/*'
请参见下面Mike DuPont的评论。我想我是在Jenkins服务器上做这件事的,这让它处于分离头部模式。
我通常只使用以下命令:
git fetch origin
git checkout --track origin/remote-branch
略短的版本:
git fetch origin
git checkout -t origin/remote-branch
如果您在fetch-all方面遇到问题,请跟踪远程分支:
git checkout --track origin/%branchname%
如果您这样做:
git fetch origin
然后他们都会在当地。如果随后执行以下操作:
git branch -a
您将看到它们列为remotes/origin/分支名称。因为他们在当地,你可以随心所欲地和他们在一起。例如:
git diff origin/branch-name
or
git merge origin/branch-name
or
git checkout -b some-branch origin/branch-name
git remote add origin https://yourBitbucketLink
git fetch origin
git checkout -b yourNewLocalBranchName origin/requiredRemoteBranch (use tab :D)
现在本地您的NewLocalBranchName是您所需的RemoteBranch。