我的主分支和开发分支在GitHub上被远程跟踪。如何克隆这两个分支?
当前回答
这个解决方案使我能够将一个存储库“复制”到另一个:
git merge path/to/source.git --mirror
cd source.git
git remote remove origin
git remote add origin path/to/target.git
git push origin --all
git push origin --tags
在目标存储库中,我可以看到与原始存储库相同的分支和标记。
其他回答
您正在执行的提取应该获取所有远程分支,但不会为它们创建本地分支。如果您使用gitk,您应该看到远程分支被描述为“remotes/origin/dev”或类似的名称。
要基于远程分支创建本地分支,请执行以下操作:
git checkout -b dev refs/remotes/origin/dev
应该返回如下内容:
Branch dev set up to track remote branch refs/remotes/origin/dev. Switched to a new branch "dev"
现在,当您在dev分支上时,“git pull”会将本地dev更新到与远程dev分支相同的位置。注意,它会取出所有的树枝,但只会将你所在的树枝拉到树的顶端。
使用您可以记住的命令
我正在使用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
您将在文档中找到有关命令的详细信息:克隆命令、获取命令、签出命令
当您执行“gitclone”时git://location“,将获取所有分支和标记。
为了在特定远程分支上工作,假设它是源远程分支:
git checkout -b branch origin/branchname
下面是另一个简短的单行命令为所有远程分支创建本地分支:
(git branch -r | sed -n '/->/!s#^ origin/##p' && echo master) | xargs -L1 git checkout
如果已经创建了跟踪本地分支,它也可以正常工作。您可以在第一个git克隆之后或以后的任何时间调用它。
如果克隆后不需要签出主分支,请使用
git branch -r | sed -n '/->/!s#^ origin/##p'| xargs -L1 git checkout
使用我的工具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
推荐文章
- 如何将git配置存储为存储库的一部分?
- 如何修改GitHub拉请求?
- 如何在Github和本地删除最后n次提交?
- 我如何调试git/git-shell相关的问题?
- 错误:无法使用rebase进行拉取:您有未分阶段的更改
- Git隐藏未缓存:如何把所有未分期的变化?
- 真实的恶魔
- 如何从另一个分支获得更改
- Git:权限被拒绝(publickey)致命-无法从远程存储库读取。克隆Git存储库时
- git reflog和log有什么区别?
- git推挂在Total line之后
- 重命名git子模块
- 结合Git存储库的前两次提交?
- Xcode 6 gitignore文件应该包括什么?
- 我如何从现有回购的分支创建一个新的GitHub回购?