假设我在git.fedorahosted.org上有一个存储库,我想将其克隆到我在github的帐户中,以拥有自己的游乐场,而不是在fedorahosted上更“官方”的回购。 最初复制的步骤是什么? 在github中有一个漂亮的“fork”按钮,但我不能使用这个明显的原因。
我如何跟踪fedorahosting回购到github的变化?
假设我在git.fedorahosted.org上有一个存储库,我想将其克隆到我在github的帐户中,以拥有自己的游乐场,而不是在fedorahosted上更“官方”的回购。 最初复制的步骤是什么? 在github中有一个漂亮的“fork”按钮,但我不能使用这个明显的原因。
我如何跟踪fedorahosting回购到github的变化?
当前回答
用下面的命令改变GIT的repo URL,简单地指向新的repo:
git remote set-url origin [new repo URL]
例如:git remote set-url origin git@bitbucket.org:Batman/batmanRepoName.git
现在,推和拉与新的回购挂钩。
然后像这样正常地推:
git push -u origin master
其他回答
这个问题的答案已经被删除了,但有一个有用的链接:https://help.github.com/articles/duplicating-a-repository
重点是
0. create the new empty repository (say, on github)
1. make a bare clone of the repository in some temporary location
2. change to the temporary location
3. perform a mirror-push to the new repository
4. change to another location and delete the temporary location
OP的例子:
在本地机器上
$ cd $HOME
$ git clone --bare https://git.fedorahosted.org/the/path/to/my_repo.git
$ cd my_repo.git
$ git push --mirror https://github.com/my_username/my_repo.git
$ cd ..
$ rm -rf my_repo.git
在github创建一个新的回购。 将repo从fedorahosted复制到本地机器。 Git远程重命名上游源 git远程添加源URL_TO_GITHUB_REPO Git push origin master
现在你可以使用它就像任何其他github回购。要从上游导入补丁,只需运行git pull upstream master && git push origin master。
将本地存储库链接到不同的远程存储库
删除与远程存储库的所有连接: 在项目文件夹内:
删除本地存储库中的所有数据 git状态(我必须说它没有链接到任何东西,有点像一个错误)
链接到一个新的远程存储库
git init启动本地存储库 Git远程添加原始urlrepository。链接到远程存储库 git remote -v确认它链接到远程存储库
3-向本地存储库添加更改并推送到远程存储库
Git pull或Git pull origin master——allow-unrelated-histories(如果本地和远程repo中的Git历史不同)。 git添加。 git commit -m" Message " Git push -u origin master
就是这样!
您真的想简单地将本地存储库(及其本地分支等)推到新的远程,还是真的想在新的远程上镜像旧的远程(及其所有分支、标记等)?如果是后者,这里有一个关于如何正确镜像git存储库的很棒的博客。
我强烈建议你阅读这篇博客,了解一些非常重要的细节,但简短的版本是这样的:
在一个新目录下运行这些命令:
git clone --mirror git@example.com/upstream-repository.git
cd upstream-repository.git
git push --mirror git@example.com/new-location.git
我用set-url找到了一个简洁易懂的解决方案:
在Github创建一个新的回购 CD到本地机器上现有的存储库中(如果您还没有克隆它,那么请先执行此操作) Git远程set-url origin https://github.com/user/example.git Git push -u origin master