如何从GitHub存储库中删除远程URL

发布于 2025-01-22 21:05:39 字数 216 浏览 4 评论 0 原文

我敢肯定,这是一个超级简单的问题,但我无法找到答案,因此我非常感谢您的答案!

我创建了一个样板存储库,我(和其他任何人)可以复制为新项目的起点。这是一个问题:当我将该存储库上传到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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一刻暧昧 2025-01-29 21:05:39

遥控器未在 github上设置;克隆时是设定的。克隆设置一个遥控器,默认情况下,这指向您用来克隆的URL。

一些选择:

  1. 首先不要克隆。

    您可以创建一个空存储库,然后从源存储库中拉出而无需设置遥控器:

      git Init foo
    CD foo
    git拉https://some.tld/foo/bar
     

    为了使这更容易,您可以创建一一都可以做到这一点,例如,将类似的东西添加到您的〜/.gitConfig

      [别名]
        clone -template =“!
     

    然后您会这样使用:

      git clone-template https://some.tld/foo/bar foo
     

    其中 foo 是您要使用的本地目录名称。

  2. 克隆,然后删除 Origin 远程:

      git克隆https://some.tld/foo/bar
    CD栏
    git Remote删除Origin
     

    为了使这更容易,您可以创建一个类似于上述操作的别名。

    棘手的部分是知道克隆创建的目录的名称,因此您可以 cd 进入其中。上面的别名要求本地目录作为参数来解决这个问题。

  3. 使用第三方工具,例如 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:

  1. Don't clone in the first place.

    You can create an empty repository and then pull from the source repository without setting a remote:

    git init foo
    cd foo
    git pull https://some.tld/foo/bar
    

    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:

    [alias]
        clone-template = "!f() { git init \"$2\" && git -C \"$2\" pull \"$1\"; }; f"
    

    Then you'd use it like this:

    git clone-template https://some.tld/foo/bar foo
    

    where foo is the local directory name you'd like to use.

  2. Clone and then remove the origin remote:

    git clone https://some.tld/foo/bar
    cd bar
    git remote remove origin
    

    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.

  3. 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 the origin as in the second option.

友谊不毕业 2025-01-29 21:05:39

检查此命令

 git remote remove origin

check this command

 git remote remove origin
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文