我的主分支和开发分支在GitHub上被远程跟踪。如何克隆这两个分支?
当前回答
每当我需要推倒所有的树枝时,我都会这样做。来自Linkedin Learning的Ray Villalobos。尝试克隆所有分支,包括提交:
mkdir -p -- newproject_folder
cd newproject_folder
git clone --mirror https://github.com/USER_NAME/RepositoryName.git .git
git config --bool core.bare false
git reset --hard
其他回答
好吧,当你克隆你的回购时,你有所有的分支。。。
如果你只是做git分支,它们是隐藏的。。。
所以,如果您想查看所有分支的名称,只需添加--all标志,如下所示:
gitbranch—all或gitbranch-a
如果你只是到分行结账,你就能得到你所需要的一切。
但是,如果你克隆后,其他人创建了分支,该怎么办?
在这种情况下,只需执行以下操作:
git获取
并再次检查所有分支。。。
如果您想同时取件和结账,可以执行以下操作:
git获取和git签出您的branch_name
还为您创建了下图,以简化我所说的内容:
#!/bin/bash
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
git branch --track ${branch#remotes/origin/} $branch
done
这些代码将把所有远程分支代码拉到本地存储库。
使用我的工具git_remote_branch(grb)。您需要在机器上安装Ruby)。它是专门为使远程分支操作非常容易而构建的。
每次它代表您执行操作时,都会在控制台上以红色打印。随着时间的推移,它们最终会进入你的大脑:-)
如果您不希望grb代表您运行命令,请使用“解释”功能。这些命令将打印到您的控制台,而不是为您执行。
最后,所有命令都有别名,以便于记忆。
注意,这是alpha软件;-)
以下是运行grb帮助时的帮助:
git_remote_branch version 0.2.6 Usage: grb create branch_name [origin_server] grb publish branch_name [origin_server] grb rename branch_name [origin_server] grb delete branch_name [origin_server] grb track branch_name [origin_server] Notes: - If origin_server is not specified, the name 'origin' is assumed (git's default) - The rename functionality renames the current branch The explain meta-command: you can also prepend any command with the keyword 'explain'. Instead of executing the command, git_remote_branch will simply output the list of commands you need to run to accomplish that goal. Example: grb explain create grb explain create my_branch github All commands also have aliases: create: create, new delete: delete, destroy, kill, remove, rm publish: publish, remotize rename: rename, rn, mv, move track: track, follow, grab, fetch
如何为远程源匹配模式上的每个分支创建本地分支。
#!/bin/sh
git fetch --all
git for-each-ref --format='%(refname:short)' refs/remotes/origin/pattern |\
sed 's@\(origin/\)\(.*\)@\2\t\1\2@' |\
xargs -n 2 git branch --track
获取所有远程引用(分支/标记),然后创建本地引用。应该可以在大多数系统上快速运行,而无需查看索引或依靠抨击。
使用您可以记住的命令
我正在使用Bitbucket,一个Atlassian的存储库托管服务。所以我试着遵循他们的文档。这对我来说非常有用。使用以下简单而简短的命令,您可以签出远程分支。
首先克隆存储库,然后转到目标文件夹。最后,但并非最不重要的是,取件和结账:
git clone <repo> <destination_folder>
cd <destination_folder>
git fetch && git checkout <branch>
就是这样。这里有一个更真实的例子:
git clone https://username@bitbucket.org/team/repository.git project_folder
cd project_folder
git fetch && git checkout develop
您将在文档中找到有关命令的详细信息:克隆命令、获取命令、签出命令
推荐文章
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?
- 跟踪所有远程git分支作为本地分支
- 自定义SSH端口上的Git
- git如何显示不存在于.gitignore中的未跟踪文件
- Git错误:遇到7个文件应该是指针,但不是
- GitHub克隆与OAuth访问令牌
- 移动(或“撤销”)最后一个git提交到非暂存区域