我的主分支和开发分支在GitHub上被远程跟踪。如何克隆这两个分支?
当前回答
如果使用Bitbucket,则可以使用import Repository。这将导入所有Git历史记录(所有分支和提交)。
其他回答
我编写了这些小PowerShell函数,以便能够签出我的所有Git分支,这些分支位于源远程。
Function git-GetAllRemoteBranches {
iex "git branch -r" <# get all remote branches #> `
| % { $_ -Match "origin\/(?'name'\S+)" } <# select only names of the branches #> `
| % { Out-Null; $matches['name'] } <# write does names #>
}
Function git-CheckoutAllBranches {
git-GetAllRemoteBranches `
| % { iex "git checkout $_" } <# execute ' git checkout <branch>' #>
}
更多的Git函数可以在我的Git设置库中找到。
我也需要做同样的事情。这是我的Ruby脚本。
#!/usr/bin/env ruby
local = []
remote = {}
# Prepare
%x[git reset --hard HEAD]
%x[git checkout master] # Makes sure that * is on master.
%x[git branch -a].each_line do |line|
line.strip!
if /origin\//.match(line)
remote[line.gsub(/origin\//, '')] = line
else
local << line
end
end
# Update
remote.each_pair do |loc, rem|
next if local.include?(loc)
%x[git checkout --track -b #{loc} #{rem}]
end
%x[git fetch]
所有分支机构
从Git项目下载所有分支的脚本
安装:
sudo git clone https://github.com/marceloviana/allBranches.git && sudo cp -rfv allBranches/allBranches.sh /usr/bin/allBranches && sudo chmod +x /usr/bin/allBranches && sudo rm -rf allBranches
准备好的现在只需调用命令(allBranches)并告诉Git项目目录,您希望下载所有分支
Use
示例1:
~$ allBranches /var/www/myproject1/
示例2:
~$ allBranches /var/www/myproject2/
示例3(如果已经在项目目录中):
~$ allBranches ./
or
~$ allBranches .
查看结果:
git branch
参考:
存储库allBranches GitHub:https://github.com/marceloviana/allBranches
如果您有许多远程分支要同时获取,请执行以下操作:
git pull --all
现在,您可以根据需要签出任何分支,而无需访问远程存储库。
注意:这不会创建任何未签出分支的工作副本,这就是问题所在。对此,请参见
大鱼的回答戴夫的回答
这个Bash脚本帮助了我:
#!/bin/bash
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
git branch --track "${branch##*/}" "$branch"
done
它将为所有远程分支创建跟踪分支,除了master(您可能从原始clone命令中得到)。我想你可能还需要
git fetch --all
git pull --all
当然
一行:gitbranch-a|grep-vHEAD|perl-ne'chomp($_);s |^\*?\s*||;如果(m|(.+)/(.+)|&¬$d{$2}){print qq(git branch--track$2$1/$2\n)}否则{$d{$_}=1}‘|csh-xfs像往常一样:在复制rm-rf宇宙之前,在您的设置中进行测试一行的积分归用户cfi
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- 在GitHub上有一个公共回购的私人分支?
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式