如何将克隆的git存储库上传到github上自己的git存储库?

5
我从github上克隆了一个项目。现在我想将它上传到我的私有仓库中以便于进行工作。但是,克隆的仓库在origin键中具有克隆项目的值。上传这个项目到我的私有仓库的最佳实践是什么?我已经阅读了git文档的德语版本(https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes),但没有找到解决方案。
2个回答

5
以下是您可以跟随的步骤:
git remote -v
git remote remove origin
git remote -v   //to check if it was remove

前往Github创建一个新的存储库。
git remote add origin <the new repository>
git remote -v

你的仓库是什么意思?你已经创建了一个仓库,并且它连接到其他项目吗?请澄清。 - Boshika Tara
是的。我已经创建了一个仓库,它只是我的私人仓库。我的意图是要建立一个网站。为此,我创建了一个私人仓库。然后,我克隆了谷歌的网站起始套件,以获得一个干净和高效的基础。现在我是这样解决的:我将我的目录初始化为git仓库。之后我创建了我的文件。然后我创建了一个新分支,在其中克隆了Google的仓库。之后我将其合并到主分支并推送到GitHub。非常感谢您的帮助。 - Mladen

2

使用该命令

git remote add newrepo NewRepoURL

你将拥有一个名为newrepo的额外远程仓库(你可以根据自己的喜好进行命名),该仓库指向NewRepoURL。要将你的分支推送到新的远程仓库(而不是上传),请执行以下操作:
git push newrepo master

我遇到了一个错误。我的存储库中只有一个README.md文件。 $ git push myrep master To https://github.com/xxxx/myrep.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/xxx/myrep.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. - Mladen
1
https://stackoverflow.com/search?q=%5Bgit%5D+%22Updates+were+rejected+because+the+remote+contains+work+that+you+do+not+have+locally%22 - phd

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接