我的主分支和开发分支在GitHub上被远程跟踪。如何克隆这两个分支?
当前回答
以下是实现此目的的最佳方法:
mkdir repo
cd repo
git clone --bare path/to/repo.git .git
git config --unset core.bare
git reset --hard
此时,您已经拥有了远程存储库及其所有分支的完整副本(使用git分支进行验证)。如果远程存储库有自己的远程设备,则可以使用--mirror而不是--bare。
其他回答
首先,克隆一个远程Git存储库并将其cd到其中:
$ git clone git://example.com/myproject
$ cd myproject
接下来,查看存储库中的本地分支:
$ git branch
* master
但您的存储库中隐藏着其他分支!使用-a标志查看这些:
$ git branch -a
* master
remotes/origin/HEAD
remotes/origin/master
remotes/origin/v1.0-stable
remotes/origin/experimental
要快速查看上游分支,请直接查看:
$ git checkout origin/experimental
要处理该分支,请创建一个本地跟踪分支,该分支通过以下方式自动完成:
$ git checkout experimental
Branch experimental set up to track remote branch experimental from origin.
Switched to a new branch 'experimental'
这里,“新分支”只是指从索引中获取分支并在本地为您创建。正如前一行告诉的那样,正在设置分支以跟踪远程分支,这通常意味着origin/branch_name分支。
您的本地分支机构现在应该显示:
$ git branch
* experimental
master
您可以使用gitremote跟踪多个远程存储库:
$ git remote add win32 git://example.com/users/joe/myproject-win32-port
$ git branch -a
* master
remotes/origin/HEAD
remotes/origin/master
remotes/origin/v1.0-stable
remotes/origin/experimental
remotes/win32/master
remotes/win32/new-widgets
在这一点上,事情变得非常疯狂,所以运行gitk看看发生了什么:
$ gitk --all &
gitclone--原始repo上的镜像很好地实现了这一点。
git clone --mirror /path/to/original.git
git remote set-url origin /path/to/new-repo.git
git push -u origin
所有分支机构
从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
现在,您可以根据需要签出任何分支,而无需访问远程存储库。
注意:这不会创建任何未签出分支的工作副本,这就是问题所在。对此,请参见
大鱼的回答戴夫的回答
Git通常(如果未指定)从一个或多个其他存储库中获取所有分支和/或标记(refs,请参见:Git-ls-refs)以及完成其历史所需的对象。换句话说,它获取已经下载的对象可以访问的对象。看:git fetch真正做什么?
有时,您可能有一些分支/标记没有直接连接到当前的分支/标记,因此git pull-all/git fetch-all在这种情况下不会有帮助,但您可以通过以下方式列出它们:
git ls-remote -h -t origin
并通过知道引用名称手动获取它们。
因此,要获取所有信息,请尝试:
git fetch origin --depth=10000 $(git ls-remote -h -t origin)
如果您对存储库进行了浅处理,--depth=10000参数可能会有所帮助。
然后再次检查所有分支:
git branch -avv
如果上述方法无效,则需要手动将丢失的分支添加到跟踪列表中(因为它们不知何故丢失了):
$ git remote -v show origin
...
Remote branches:
master tracked
通过git远程设置分支,如:
git remote set-branches --add origin missing_branch
因此在获取后,它可能出现在remotes/origin下:
$ git remote -v show origin
...
Remote branches:
missing_branch new (next fetch will store in remotes/origin)
$ git fetch
From github.com:Foo/Bar
* [new branch] missing_branch -> origin/missing_branch
故障排除
如果您仍然无法获得主分支以外的任何内容,请检查以下内容:
仔细检查遥控器(gitremote-v),例如。验证git-config-branch.master.remote是源代码。通过:git remote show origin检查origin是否指向正确的URL(参见本文)。
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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日志日期格式