我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:

$ git branch
* master

我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?

$ git branch
* master
* staging
* etc...

当前回答

要列出远程分支,请执行以下操作:

git branch -r

要将远程分支签出为本地分支,请执行以下操作:

git checkout -b local_branch_name origin/remote_branch_name

其他回答

|‾‾‾‾‾‾‾‾‾‾‾‾‾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

我用这个命令拉动原点分支,git拉动原点

git remote add origin https://yourBitbucketLink

git fetch origin

git checkout -b yourNewLocalBranchName origin/requiredRemoteBranch (use tab :D)

现在本地您的NewLocalBranchName是您所需的RemoteBranch。

要列出远程分支,请执行以下操作:

git branch -r

要将远程分支签出为本地分支,请执行以下操作:

git checkout -b local_branch_name origin/remote_branch_name

确保所有远程分支都可以在.git/config文件中获取。

在本例中,只有原始/生产分支是可获取的,即使您尝试执行git fetch,除了获取生产分支之外,一切都不会发生:

[origin]
fetch = +refs/heads/production:refs/remotes/origin/production

该行应替换为:

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

然后运行git fetch等。。。