我的主分支和开发分支在GitHub上被远程跟踪。如何克隆这两个分支?
当前回答
要创建存储在git主机(github/bitbucket/etc)中的所有分支+引用+标记+等的“完整”备份,请运行:
mkdir -p -- myapp-mirror
cd myapp-mirror
git clone --mirror https://git.myco.com/group/myapp.git .git
git config --bool core.bare false
git config --bool core.logAllRefUpdates true
git reset --hard # restore working directory
这是根据我从其他答案中学到的一切整理而成的。
然后,您可以使用此本地回购镜像转换到不同的SCM系统/git主机,也可以将其作为备份。它作为搜索工具也很有用,因为大多数git主机只搜索每个repo的“main”分支上的代码,如果您使用git log-s“specialVar”,您将看到所有分支上的所有代码。
注意:如果您想在日常工作中使用此回购,请运行:
git config --unset remote.origin.mirror
警告:如果你试图在日常工作中使用它,你可能会遇到奇怪的问题。如果您的ide/编辑器正在进行一些自动提取,您的本地主控器可能会更新,因为您做了gitclone--mirror。然后这些文件会出现在git暂存区。事实上,我有一种情况,我在当地的一个特色分支。。该分支没有提交,repo中的所有文件都显示在暂存区域中。只是疯子。
其他回答
使用我的工具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
这并不太复杂。非常简单明了的步骤如下:;
gitfetchorigin:这将把所有远程分支带到本地。
gitbranch-a:这将显示所有远程分支。
git checkout--跟踪origin/<要签出的分支>
通过以下命令验证您是否在所需的分支中;
git branch
输出将是这样的;
*your current branch
some branch2
some branch3
请注意表示当前分支的*符号。
gitclone--原始repo上的镜像很好地实现了这一点。
git clone --mirror /path/to/original.git
git remote set-url origin /path/to/new-repo.git
git push -u origin
使用您可以记住的命令
我正在使用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
您将在文档中找到有关命令的详细信息:克隆命令、获取命令、签出命令
首先,克隆一个远程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 &
推荐文章
- 撤消git平分错误
- 使用.gitconfig配置diff工具
- 如何配置Mac OS X术语,使git有颜色?
- Visual Studio Code: .git文件夹/文件隐藏
- “node_modules”文件夹应该包含在git存储库中吗
- 为什么git-rebase给了我合并冲突,而我所做的只是压缩提交?
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 如何从远程分支中挑选?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖