我正在尝试使用linux将整个存储库克隆到我的机器上.我用了
git clone <url>
Run Code Online (Sandbox Code Playgroud)
然后我进入了下载和输入的文件夹
git branch
Run Code Online (Sandbox Code Playgroud)
在终端.它只显示我的主人,而不是显示在远程存储库中的其他分支.如何克隆所有分支?
我知道对于遥控器中的每个分支我都可以单独使用
git checkout -b <name of local branch> origin/<name of remote branch>
Run Code Online (Sandbox Code Playgroud)
但除此之外有什么办法吗?
nhu*_*uvy 48
(1)在git local repostitory中,创建一个新的sh文件
touch getAllBranches.sh
vi getAllBranches.sh
Run Code Online (Sandbox Code Playgroud)
(2)将以下内容插入getAllBranches.sh
文件:
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
git branch --track ${branch#remotes/origin/} $branch
done
Run Code Online (Sandbox Code Playgroud)
(3)获得所有分支:
chmod +x getAllBranches.sh
sh getAllBranches.sh
Run Code Online (Sandbox Code Playgroud)
(4)检查本地存储库的结果:
git branch
Run Code Online (Sandbox Code Playgroud)
例如,我使用存储库:https://github.com/donhuvy/spring-boot
如您所见,我已经将所有分支都提取到本地机器:
Ami*_*pta 38
这不是太复杂,非常简单和直接的步骤如下:
克隆回购后,运行 $ cd myproject
git branch -a
这将显示所有远程分支.
$ git branch -a
* master
remotes/origin/HEAD
remotes/origin/master
remotes/origin/v1.0-stable
remotes/origin/experimental
Run Code Online (Sandbox Code Playgroud)
如果要在远程分支上工作,则需要创建本地跟踪分支:
$ git checkout -b experimental origin/experimental
Run Code Online (Sandbox Code Playgroud)
通过以下命令验证您是否在所需的分支中;
$ git branch
Run Code Online (Sandbox Code Playgroud)
输出将是这样的;
*experimental
master
some branch2
some branch3
Run Code Online (Sandbox Code Playgroud)
注意表示当前分支的*符号.
Ame*_* Ra 13
git clone --bare <repository url goes here> .git
Run Code Online (Sandbox Code Playgroud)
然后在repo克隆其所有分支后,执行以下操作
git config --bool core.bare false
git reset --hard
Run Code Online (Sandbox Code Playgroud)
Xio*_*iov 12
它只显示我的主人,而不是显示在远程存储库中的其他分支.如何克隆所有分支?
分支基本上是提交的指针.当您执行git clone
(或a git fetch
)时,您将从远程存储库及其所有分支中检索所有提交.
但是,git branch
默认情况下不显示远程分支.相反,它会向您显示您的本地分支,这些分支可能与远程上存在的分支有任何关系.如果你运行git branch --all
,git将报告它所知道的所有分支,包括本地和远程.
值得注意的是,标签不以这种方式运行,并且本地标签和远程标签之间没有区别.
我发现这是克隆 git 存储库和所有远程分支的简单解决方案:
# Clone remote repository and all branches
git clone --mirror https://github.com/test/frontend.git frontend/.git
# Change into frontend directory
cd frontend
# Update git config
git config --unset core.bare
# Checkout master branch
git checkout master
Run Code Online (Sandbox Code Playgroud)
小智 5
git clone --bare https://repo.git projectName
cd projectName
git push --mirror https://repo.git
这使得您的存储库完全相同。
请参阅: https: //help.github.com/en/articles/duplicating-a-repository
归档时间: |
|
查看次数: |
44994 次 |
最近记录: |