假设我在git.fedorahosted.org上有一个存储库,我想将它克隆到我在github的帐户中,除了fedorahosted上更“官方”的回购之外,还有我自己的游乐场。最初复制它的步骤是什么?在github中有一个很好的“fork”按钮,但由于显而易见的原因,我无法使用它。
我如何跟踪fedorahosted repo中的变化到github one?
git remote rename origin upstream
git remote add origin URL_TO_GITHUB_REPO
git push origin master
现在你可以像任何其他github repo一样使用它。要从上游提取补丁,只需运行git pull upstream master && git push 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
要将现有的仓库推送到不同的仓库,您需要:
git clone https://git.fedorahosted.org/cgit/rhq/rhq.git
cd rhq
git push https://github.com/user/example master:master
你可以将master:master
改成source:destination
分支。
如果要推送特定的提交(分支),那么执行:
git checkout -b new_branch
git log # Find the interesting hash
git reset 4b62bdc9087bf33cc01d0462bf16bbf396369c81 --hard
或者,选择git cherry-pick
提交以附加到现有HEAD中。git push https://github.com/user/example new_branch:master
如果您正在变基础,请使用-f
进行强制推动(不推荐)。运行git reflog
以查看更改历史记录。你真的想简单地将你的本地存储库(带有本地分支机构等)推送到新的遥控器,还是你真的想要在新的遥控器上镜像旧遥控器(及其所有分支,标签等)?如果后者在这里是关于How to properly mirror a git repository的一个很棒的博客。
我强烈建议您阅读博客中的一些非常重要的细节,但简短的版本是这样的:
在新目录中运行以下命令:
git clone --mirror [email protected]/upstream-repository.git
cd upstream-repository.git
git push --mirror [email protected]/new-location.git
试试这个How to move a full Git repository
git branch -a
git checkout branch-name
git fetch --tags
git tag
git branch -a
git remote rm origin
git remote add origin <url to NEW repo>
git push origin --all
git push --tags
我找到了一个使用set-url的解决方案,它简洁易懂:
cd
进入本地计算机上的现有存储库(如果尚未克隆它,请先执行此操作)git remote set-url origin https://github.com/user/example.git
git push -u origin master
如果您有Existing Git存储库:
cd existing_repo
git remote rename origin old-origin
git remote add origin https://gitlab.com/newproject
git push -u origin --all
git push -u origin --tags
我曾经也有过一样的问题。
在我的情况下,因为我在本地机器中有原始存储库,所以我在新文件夹中制作了一个没有任何隐藏文件(.git,.gitignore)的副本。
最后,我将.gitignore文件添加到新创建的文件夹中。
然后我从本地路径创建并添加了新的存储库(在我的例子中使用GitHub Desktop)。
只需使用以下命令更改GIT repo URL即可指向新的repo:
git remote set-url origin [new repo URL]
示例:git remote set-url origin [email protected]:Batman/batmanRepoName.git
现在,推动和拉动与新的REPO相关联。
然后像这样正常推送:
git push -u origin master