我的主分支和开发分支在GitHub上被远程跟踪。如何克隆这两个分支?
当前回答
我编写了这些小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设置库中找到。
其他回答
git克隆应该复制整个存储库。尝试克隆它,然后运行gitbranch-a。它应该列出所有分支。如果您想切换到分支“foo”而不是“master”,请使用git checkout foo。
当您执行“gitclone”时git://location“,将获取所有分支和标记。
为了在特定远程分支上工作,假设它是源远程分支:
git checkout -b branch origin/branchname
我正在用Python和Pytest从Udemy课程Elegant Automation Frameworks中克隆一个存储库,以便以后可以离线查看。我尝试下载zip,但这只适用于当前分支,因此这是我的2美分。
我在Windows上工作,显然,我求助于Windows Subsystem for Linux中的Ubuntu shell。克隆完成后,我的分支如下:
$ git clone https://github.com/BrandonBlair/elegantframeworks.git
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/config_recipe
remotes/origin/functionaltests
remotes/origin/master
remotes/origin/parallel
remotes/origin/parametrize
remotes/origin/parametrize_data_excel
remotes/origin/unittesting
remotes/origin/unittesting1
然后,在撞了几块几位数的结账砖墙之后,我终于明白了:
$ for b in `git branch -a | cut -c18- | cut -d\ -f1`; do git checkout $b; git stash; done
在此之后,以下是我的分支:
$ git branch -a
config_recipe
functionaltests
master
parallel
parametrize
parametrize_data_excel
unittesting
* unittesting1
remotes/origin/HEAD -> origin/master
remotes/origin/config_recipe
remotes/origin/functionaltests
remotes/origin/master
remotes/origin/parallel
remotes/origin/parametrize
remotes/origin/parametrize_data_excel
remotes/origin/unittesting
remotes/origin/unittesting1
我的是物理的,去掉了最初的遥控器/原点,然后过滤空间分隔符。可以说,我本可以把HEAD去掉,只剪一刀,但我会留给评论。
请注意,您当前的分支机构现在是列表中的最后一个。如果你不知道这是为什么,那你的处境就很艰难。现在你想要什么就结账吧。
使用我的工具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
每当我需要推倒所有的树枝时,我都会这样做。来自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
推荐文章
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?
- 跟踪所有远程git分支作为本地分支
- 自定义SSH端口上的Git
- git如何显示不存在于.gitignore中的未跟踪文件
- Git错误:遇到7个文件应该是指针,但不是
- GitHub克隆与OAuth访问令牌
- 移动(或“撤销”)最后一个git提交到非暂存区域