我如何克隆一个git存储库并保存远程? [英] How can I clone a git repository and keep remotes?

查看:127
本文介绍了我如何克隆一个git存储库并保存远程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我创建了一个git仓库,在我的工作副本上设置了一些标签和遥控器,然后使用

  git push --mirror my.remote.repository 

假设使用git --mirror还会推送我设置的遥控器。



然而,如果我做了

  git clone my.remote.repository 

我没有看到我最初创建的遥控器。我是否需要特殊的语法来克隆遥控器?镜子没有实际发送遥控器吗?我在哪里出了问题?



编辑:也许我的工作流程很奇怪:这就是我想要完成的。
回购最初是另一个项目(A)的克隆,我无法控制,我已将远程更名为上游。我创建了一个新的'主'分支,并打算对我的工作副本进行更改并部署它们。我偶尔会从原始存储库(A)中提取更新(切换到原始未修改的分支并从上游提取)。但是,我正在与其他人一起工作,他们都应该能够做到这一点。目标是通过初始仓库(A)中的错误修复来更新主分支,并将更改提交到主分支。因此,当开发人员克隆存储库时,他们应该继承上游分支,以便他们实际执行此操作。总之,我试图使用上游分支来从不同项目中获取更新。我没有使用子模块来做到这一点,因为上游分支实际上负责存储库中95%的文件,如果没有来自上游的文件,整个项目就没有意义。


< (这不是一个典型的工作流程,但我会尝试回答直接的问题......)

git push --mirror 确实会将您的远程追踪分支推送到远程的相同名称。但是,在克隆时,默认情况下,您只需获取 refs / heads 下的ref,它们被映射到 refs / remotes /原点/ 。你可以克隆 git clone --mirror 以从远程获得远程追踪分支,但该选项意味着 - 裸露

如果你想要一个工作树的存储库,其分支是从远程镜像的,你总是可以改变config选项中的refspec remote.origin.fetch 将每个参考文献取回到同一个名称,但我怀疑真正的问题是您使用的是非常不寻常的工作流程。



顺便说一下,即使您使用其中一种技术来更改所提取的ref的映射,它也不会自己克隆 remotes ,它们在存储库的git config - git clone 不会克隆 .git / config 中的任何内容,它被认为包含私有信息。

So I've created a git repository, set up some tags and remotes on my working copy, and then pushed the repository to my server with

git push --mirror my.remote.repository

Supposedly, pushing with git --mirror will also push the remotes that I've set up.

However, if I do

git clone my.remote.repository

I don't see the remotes that I created originally. Do I need special syntax to also clone the remotes? Does mirror not actually send remotes? Where did I go wrong?

Edit: Maybe my workflow is weird: Here's what I'm trying to accomplish. The repo is initially a clone of another project(A) that I don't control, where I've renamed the remote to 'upstream'. I've made a new 'master' branch, and intend to make changes to my working copy and deploy them. I will occasionally pull updates from the original repository (A) (switching to the original, unmodified branch and pulling from upstream). However, I'm working with other people, all of whom should be able to do this as well. The goal is to update the master branch with bug fixes from the initial repository(A) and commit the changes to the 'master' branch. Because of this, when a developer clones the repository, they should be inheriting the upstream branch so that they can actually do this. In short, I'm trying to use an 'upstream' branch to pull in updates from a different project. I haven't used a submodule to do this since the 'upstream' branch actually is responsible for 95% of the files in the repository and the entire project makes no sense without the files from upstream.

解决方案

(This isn't a typical workflow, but I'll try to answer the direct question anyway...)

git push --mirror will indeed have pushed your remote-tracking branches to the same name on the remote. However, when you clone, you by default only get the refs under refs/heads, which are mapped to remote-tracking branches under refs/remotes/origin/. You could clone with git clone --mirror to get the remote-tracking branches from the remote as well, but that option implies --bare.

If you want a repository with a working tree whose branches are mirrored from the remote, you could always change the refspec in the config option remote.origin.fetch to fetch every ref to the same name, but again I suspect that the real problem is that you're using a very unusual workflow.

Incidentally, even if you use one of those techniques to change the mapping of the refs that are fetched, this won't clone the remotes themselves, which are defined in the repository's git config - git clone doesn't clone anything from .git/config, which is considered to contain private information.

这篇关于我如何克隆一个git存储库并保存远程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆