我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:
$ git branch
* master
我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?
$ git branch
* master
* staging
* etc...
我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:
$ git branch
* master
我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?
$ git branch
* master
* staging
* etc...
当前回答
设置别名:(基于顶部答案)
git config --global alias.track-all-branches '!git fetch --all && for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done && git fetch --all'
现在要跟踪所有分支:
git跟踪所有分支
其他回答
$ git remote update
$ git pull --all
这假设所有分支都被跟踪。
如果他们不是,你可以在Bash中发射这个:
for remote in `git branch -r `; do git branch --track $remote; done
然后运行命令。
注意:请阅读下面的警告注释。
我相信您已经通过以下方式克隆了存储库:
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}
您需要创建跟踪远程分支的本地分支。
假设您只有一个名为origin的远程,此代码片段将为所有远程跟踪分支创建本地分支:
for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done
之后,gitfetch-all将更新远程分支的所有本地副本。
此外,gitpull-all将更新您的本地跟踪分支,但根据您的本地提交以及“合并”配置选项的设置方式,它可能会创建一个合并提交、快进或失败。
对于使用PowerShell的Windows用户:
git branch -r | ForEach-Object {
# Skip default branch, this script assumes
# you already checked-out that branch when cloned the repo
if (-not ($_ -match " -> ")) {
$localBranch = ($_ -replace "^.*?/", "")
$remoteBranch = $_.Trim()
git branch --track "$localBranch" "$remoteBranch"
}
}; git fetch --all; git pull --all