git 从别人的 Github 克隆一个 repo 并将其推送到我的 Github 上的一个 repo

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18200248/
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-10 16:45:33  来源:igfitidea点击:

Cloning a repo from someone else's Github and pushing it to a repo on my Github

gitgithub

提问by Hymanerman09

I cloned the repo at https://github.com/railstutorial/sample_app_rails_4and made a lot of changes to it (I used it as a starting point for my own app), and now I would like to push the changed app to a repo on my own github account.

我在https://github.com/railstutorial/sample_app_rails_4克隆了 repo并对其进行了大量更改(我将其用作我自己应用程序的起点),现在我想将更改后的应用程序推送到回购在我自己的 github 帐户上。

How can I change what github repo it is linked to?

如何更改它链接到的 github 存储库?

回答by mgarciaisaia

As Deefour says, your situation isn't much unlike the one in Change the URI (URL) for a remote Git repository. When you clonea repository, it is added as a remoteof yours, under the name origin. What you need to do now (as you're not using the old source anymore) is change origin's URL:

正如 Deefour 所说,您的情况与更改远程 Git 存储库的 URI (URL) 中的情况没有太大不同。当您clone是存储库时,它会作为您的一个添加remote到名称下origin。您现在需要做的(因为您不再使用旧源)是 changeorigin的 URL:

$ git remote set-url origin http://github.com/YOU/YOUR_REPO

If the original repository would update often and you want to get those updates from time to time, then instead of editing originit would be best to add a new remote:

如果原始存储库经常更新并且您希望不时获得这些更新,那么origin最好添加一个新的而不是编辑remote

$ git remote add personal http://github.com/YOU/YOUR_REPO

Or maybe even call the old one upstream:

或者甚至可以调用旧的upstream

$ git remote rename origin upstream
$ git remote add origin http://github.com/YOU/YOUR_REPO

Then, whenever you want to get changes from upstream, you can do:

然后,无论何时您想从 获取更改upstream,您都可以执行以下操作:

$ git fetch upstream

As this the source is a sample repository (seems to be kind of a template to start off), I don't think there's a need to keep it nor fork it at all - I'll go with the first alternative here.

由于这个源是一个示例存储库(似乎是一种开始的模板),我认为根本不需要保留它或分叉它 - 我将在这里使用第一个替代方案。

回答by Derek Soike

GitHub: git clonesomeone else's repository & git pushto your own repository

GitHub:git clone别人的仓库 &git push到你自己的仓库

I'm going to refer to someone else'srepository as the other repository.

我将把其他人的仓库称为other repository



  1. Create a new repository at github.com.(this is your repository)

    • Give it the same name as the other repository.
    • Don't initialize it with a README, .gitignore, or license.
  2. Clone the other repositoryto your local machine.(if you haven't done so already)

    • git clone https://github.com/other-account/other-repository.git
  3. Rename the local repository's current 'origin' to 'upstream'.

    • git remote rename origin upstream
  4. Give the local repository an 'origin' that points to your repository.

    • git remote add origin https://github.com/your-account/your-repository.git
  5. Push the local repository to your repositoryon github.

    • git push origin master
  1. github.com 上创建一个新存储库。(这是您的存储库

    • 为其指定与其他存储库相同的名称。
    • 不要使用 README、.gitignore 或许可证对其进行初始化。
  2. 另一个存储库克隆到本地计算机。(如果你还没有这样做)

    • git clone https://github.com/other-account/other-repository.git
  3. 将本地存储库的当前“ origin”重命名为“ upstream”。

    • git remote rename origin upstream
  4. 为本地存储库提供一个指向您的存储库的“原点” 。

    • git remote add origin https://github.com/your-account/your-repository.git
  5. 将本地存储库推送到在 github上的存储库

    • git push origin master


Now 'origin' points to your repository& 'upstream' points to the other repository.

现在' origin' 指向您的存储库,' upstream' 指向另一个存储库

  • Create a new branch for your changes with git checkout -b my-feature-branch.
  • You can git commitas usual to your repository.
  • Use git pull upstream masterto pull changes from the other repositoryto your master branch.
  • 使用 为您的更改创建一个新分支git checkout -b my-feature-branch
  • 您可以git commit像往常一样访问您的存储库
  • 使用git pull upstream master以拉从改变其他仓库到你的主分支。

回答by MAOXU

Delete git and re-init.

删除 git 并重新初始化。

Your purpose is probably to put this repo on yours and make it yours.

你的目的可能是把这个 repo 放在你的身上并让它成为你的。

The idea is to delete the .git/and re-initialize.

这个想法是删除.git/并重新初始化。

  1. go to your cloned repo folder rm -rf .git
  2. re-initialize it and then add your remote and do your first push.
    git init
    git add .
    git commit -m "your commit message"
    git remote add origin 
    git push origin master
    
  1. 转到您克隆的 repo 文件夹 rm -rf .git
  2. 重新初始化它,然后添加您的遥控器并进行第一次推送。
    git init
    git add .
    git commit -m "your commit message"
    git remote add origin 
    git push origin master
    

回答by bmorgan21

You can do this by creating a new remote from your local repository (via commandline).

您可以通过从本地存储库(通过命令行)创建新的远程来完成此操作。

git remote add <name> <url>

then you can call:

然后你可以打电话:

git push <name> <repo_name>

To replace the default "origin" remote that is set up you can run the following:

要替换设置的默认“origin”远程,您可以运行以下命令:

git remote rm origin
git remote add origin <url>

回答by llekn

I think that the "most polite way" to do so would be:

我认为这样做的“最礼貌的方式”是:

  1. Fork the original repo on your GitHub account
  2. Checkout a new branch for your changes git checkout -b <your_branch_name>(in case you didn't do that before)
  3. Add a new remote for your local repository: git remote add github <your_repository_ssh_url>
  4. Push your beautiful new branch to your github repository: git push github <your_branch_name>
  1. 在您的 GitHub 帐户上分叉原始存储库
  2. 为您的更改签出一个新分支git checkout -b <your_branch_name>(以防您之前没有这样做)
  3. 为您的本地存储库添加一个新的远程: git remote add github <your_repository_ssh_url>
  4. 将您漂亮的新分支推送到您的 github 存储库: git push github <your_branch_name>

In this way you will have a repo forked to the original one, with your changes commited in a separate branch. This way will be easier in case you want to submit a pull request to the original repo.

通过这种方式,您将拥有一个分叉到原始存储库的存储库,并将您的更改提交到一个单独的分支中。如果您想向原始存储库提交拉取请求,这种方式会更容易。

回答by Eric C

Taken from Git push everything to new origin

取自 Git 将所有内容推送到新的原点

basically you have to associate a new repo to your folder

基本上你必须将一个新的 repo 关联到你的文件夹

git remote add origin <address>
git push origin <branchname>

回答by F. X. Blankson

After cloning, copy the files from their folder into a new one and start afresh with git init,

克隆后,将文件夹中的文件复制到一个新文件夹中,然后使用 git init 重新开始,

I had a similar problem like that I had to change folder directory before I could stage the changes to my repo

我有一个类似的问题,我必须先更改文件夹目录,然后才能对我的 repo 进行更改

回答by user3685927

I had a similar situation, but in my case what I just needed to do was, as suggested, but with https, like this:

我有类似的情况,但在我的情况下,我只需要按照建议做的是,但是使用https,如下所示:

$ git remote set-url origin https://github.com/YOU/YOUR_REPO

$ git remote set-url origin https://github.com/YOU/YOUR_REPO