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
Cloning a repo from someone else's Github and pushing it to a repo on my Github
提问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 clone
a repository, it is added as a remote
of 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 origin
it 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 clone
someone else's repository & git push
to your own repository
GitHub:git clone
别人的仓库 &git push
到你自己的仓库
I'm going to refer to someone else'srepository as the other repository.
我将把其他人的仓库称为other repository。
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.
Clone the other repositoryto your local machine.(if you haven't done so already)
git clone https://github.com/other-account/other-repository.git
Rename the local repository's current 'origin' to 'upstream'.
git remote rename origin upstream
Give the local repository an 'origin' that points to your repository.
git remote add origin https://github.com/your-account/your-repository.git
Push the local repository to your repositoryon github.
git push origin master
在github.com 上创建一个新存储库。(这是您的存储库)
- 为其指定与其他存储库相同的名称。
- 不要使用 README、.gitignore 或许可证对其进行初始化。
将另一个存储库克隆到本地计算机。(如果你还没有这样做)
git clone https://github.com/other-account/other-repository.git
将本地存储库的当前“ origin”重命名为“ upstream”。
git remote rename origin upstream
为本地存储库提供一个指向您的存储库的“原点” 。
git remote add origin https://github.com/your-account/your-repository.git
将本地存储库推送到您在 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 commit
as usual to your repository. - Use
git pull upstream master
to 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/
并重新初始化。
- go to your cloned repo folder
rm -rf .git
- 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
- 转到您克隆的 repo 文件夹
rm -rf .git
- 重新初始化它,然后添加您的遥控器并进行第一次推送。
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:
我认为这样做的“最礼貌的方式”是:
- Fork the original repo on your GitHub account
- Checkout a new branch for your changes
git checkout -b <your_branch_name>
(in case you didn't do that before) - Add a new remote for your local repository:
git remote add github <your_repository_ssh_url>
- Push your beautiful new branch to your github repository:
git push github <your_branch_name>
- 在您的 GitHub 帐户上分叉原始存储库
- 为您的更改签出一个新分支
git checkout -b <your_branch_name>
(以防您之前没有这样做) - 为您的本地存储库添加一个新的远程:
git remote add github <your_repository_ssh_url>
- 将您漂亮的新分支推送到您的 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
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