我敢肯定,这是一个超级简单的问题,但我无法找到答案,因此我非常感谢您的答案!
我创建了一个样板存储库,我(和其他任何人)可以复制为新项目的起点。这是一个问题:当我将该存储库上传到GitHub时,我显然需要设置远程URL。但是,当某人(例如我)克隆存储库并进行更改时,在不设置自己的URL的情况下推动更改很容易,因此将更改推向原始样板。
如何从存储库中删除远程URL并仍在GitHub上托管?
I'm sure this is a super simple question but I wasn't able to find an answer to it, so I'm extremely grateful for your answers!
I have created a boilerplate repository that I (and anybody else) can copy as a starting point for a new project. Here's the problem: when I upload that repository to Github, I obviously need to set the remote URL. However, when someone (me, for example) clones the repository and makes changes, it's easy to push the changes without setting up your own URL, and therefore push changes to the original boilerplate.
How can I remove the remote URL from the repository and still host it on Github?
发布评论
评论(2)
遥控器未在 github上设置;克隆时是设定的。克隆设置一个遥控器,默认情况下,这指向您用来克隆的URL。
一些选择:
首先不要克隆。
您可以创建一个空存储库,然后从源存储库中拉出而无需设置遥控器:
为了使这更容易,您可以创建一一都可以做到这一点,例如,将类似的东西添加到您的
〜/.gitConfig
:然后您会这样使用:
其中
foo
是您要使用的本地目录名称。克隆,然后删除
Origin
远程:为了使这更容易,您可以创建一个类似于上述操作的别名。
棘手的部分是知道克隆创建的目录的名称,因此您可以
cd
进入其中。上面的别名要求本地目录作为参数来解决这个问题。使用第三方工具,例如
degit 没有历史的克隆。
这里的主要缺点是(a)具有第三方依赖性,可能使用您不想设置的开发堆栈,以及(b)失去所有提交历史记录以及遥控器。
您可以通过执行
git克隆 - depth = 1
之类的操作来缓解(a)你的历史。如果您要这样做,我建议您像第二个选项中的Origin
。一样。
The remote isn't set on GitHub; it's set when you clone. Cloning sets up a remote, called
origin
by default, that points to the URL you used to clone.A few options:
Don't clone in the first place.
You can create an empty repository and then pull from the source repository without setting a remote:
To make this easier, you could create an alias that does it all in one go, e.g. by adding something like this to your
~/.gitconfig
:Then you'd use it like this:
where
foo
is the local directory name you'd like to use.Clone and then remove the
origin
remote:To make this easier, you could create an alias that does both operations, as above.
The tricky part there is knowing the name of the directory that was created by the clone so you can
cd
into it. The alias above requires the local directory as an argument to get around this.Use a third-party tool like
degit
that clones without history.The main disadvantages here are (a) having a third-party dependency, possibly using a dev stack you don't want to set up, and (b) losing all commit history as well as the remote.
You can mitigate against (a) by doing something like
git clone --depth=1
followed by removing the.git/
directory, but this will still nuke all your history. If you're going to do this, I suggest you just unset theorigin
as in the second option.检查此命令
check this command