我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:
$ git branch
* master
我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?
$ git branch
* master
* staging
* etc...
我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:
$ git branch
* master
我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?
$ git branch
* master
* staging
* etc...
当前回答
克隆主存储库后,您只需执行
git fetch && git checkout <branchname>
其他回答
$ git remote update
$ git pull --all
这假设所有分支都被跟踪。
如果他们不是,你可以在Bash中发射这个:
for remote in `git branch -r `; do git branch --track $remote; done
然后运行命令。
注意:请阅读下面的警告注释。
以下是我认为可靠的东西:
不更新现有分支的远程跟踪不尝试更新HEAD以跟踪原点/HEAD允许命名为非原点的远程正确引用外壳
for b in $(git branch -r --format='%(refname:short)'); do
[[ "${b#*/}" = HEAD ]] && continue
git show-ref -q --heads "${b#*/}" || git branch --track "${b#*/}" "$b";
done
git pull --all
不需要git fetch,因为将all传递给git pull会将此选项传递给内部fetch。
这个答案值得称赞。
玩git时要小心,循序渐进。
$ git remote update //This will update your local
$ git branch -a //This will list all the branches(After updating you can now
see the new branch in the list)
$ git checkout your_branch_name
我相信您已经通过以下方式克隆了存储库:
git clone https://github.com/pathOfrepository
现在使用cd转到该文件夹:
cd pathOfrepository
如果键入gitstatus,您可以看到所有:
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
要查看所有隐藏的分支类型,请执行以下操作:
git branch -a
它将列出所有远程分支。
现在,如果您想在任何特定分支上签出,只需键入:
git checkout -b localBranchName origin/RemteBranchName
对于Visual Studio用户,在包管理器控制台上:
git branch | %{ git fetch upstream; git merge upstream/master}