将 git 存储库移动到另一个 github 用户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14131940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:58:09  来源:igfitidea点击:

Move git repository to another github user

gitversion-controlgithub

提问by dchacke

There are many answers on Google that point in the same direction, but when it comes to version control I don't want to try anything and then mess up my repository.

Google 上有很多答案都指向相同的方向,但是当涉及到版本控制时,我不想尝试任何事情然后弄乱我的存储库。

I have set up a repository on GitHub and would like to move it to another user, so that I can close the repository. He would then invite me to the repo once it belongs to his account. I guess this is quite a common use case for working with clients - once you finished the project, you hand it over to them.

我已在 GitHub 上设置了一个存储库,并希望将其移至另一个用户,以便我可以关闭该存储库。一旦它属于他的帐户,他就会邀请我加入回购。我想这是与客户合作的一个很常见的用例——一旦你完成了项目,你就把它交给他们。

Now, assuming this is possible, how would I change my local Git settings in the project so that I am now pushing to/pulling from the new location? And, by moving the repo, would I lose the commit history?

现在,假设这是可能的,我将如何更改项目中的本地 Git 设置,以便我现在推入/拉出新位置?而且,通过移动回购,我会丢失提交历史吗?

采纳答案by xero

Any of the following will work:

以下任何一项都将起作用:

  • Just transfer ownership of the repo to another user and have them add you as a collaborator.

  • If someone forks your repo, then you delete the original, their fork is still there, unless it's a private repository. they can then add you as a collaborator on their fork repo.

  • Another user can simply clone your repo (commits intact), create a new repo on GitHub, add the new repo's remote info, and push your repo up to their new one. (Then, they can add you as a collaborator.)

  • 只需将 repo 的所有权转让给另一个用户,并让他们将您添加为合作者。

  • 如果有人 fork 你的 repo,那么你删除原来的,他们的 fork 仍然存在,除非它是一个 private repository。然后他们可以将您添加为他们的 fork 存储库的合作者。

  • 另一个用户可以简单地克隆您的存储库(完整提交),在 GitHub 上创建一个新存储库,添加新存储库的远程信息,并将您的存储库推送到他们的新存储库。(然后,他们可以将您添加为合作者。)

回答by citruspi

To answer the questions:

回答问题:

  1. You would not lose anything - not even commit history. The point of Git is that it is decentralized - everybody with a copy of the repository has everything. Just the new repo.

  2. It is easy to change the git settings to push to the new repository. You can either use

    git remote set-url origin git://new.url.here
    

    or edit the .git/configfile.

  1. 你不会失去任何东西——甚至不会提交历史。Git 的重点在于它是去中心化的——每个拥有存储库副本的人都拥有一切。只是新的回购。

  2. 更改 git 设置以推送到新存储库很容易。你可以使用

    git remote set-url origin git://new.url.here
    

    或编辑.git/config文件。

I would say you should:

我会说你应该:

  1. Transfer ownership of the repository (or have the client fork it).
  2. Change your git config to push to the new repository
  3. You're done.
  1. 转让存储库的所有权(或让客户对其进行分叉)。
  2. 更改您的 git 配置以推送到新存储库
  3. 你完成了。

回答by the.malkolm

Why don't you do it within github? Just transfer ownership to the new user. Go to Settings at Github.

你为什么不在github中做呢?只需将所有权转让给新用户。转到 Github 的设置。

Transfer Ownership: Transfer this repo to another user or to an organization where you have admin rights.

转让所有权:将此存储库转让给另一个用户或您拥有管理员权限的组织。

回答by matt

You would not lose anything. That's the point of git. Every copy of the project has a complete copy of the repo - you have it, github has it, anyone who forks it has it.

你不会失去任何东西。这就是 git 的意义所在。项目的每个副本都有一个完整的 repo 副本——你有它,github 有它,任何 fork 的人都有它。

The configuration of the remote is just a line in the .git/config file:

远程的配置只是 .git/config 文件中的一行:

    url = [email protected]:mattneub/Programming-iOS-Book-Examples.git

You can remove the old remote and create a new one, but the simplest thing is just to edit that line by hand.

您可以移除旧遥控器并创建一个新遥控器,但最简单的方法就是手动编辑该行。

There is no mystery here. The .git folder and your repository are directly open to your view.

这里没有什么神秘之处。.git 文件夹和您的存储库直接打开您的视图。