Git是否将现有的repo推送到新的、不同的远程repo服务器?
假设我在上有一个存储库,我想将它克隆到我在github的帐户中,除了fedorahosted上更“正式”的回购协议之外,还有我自己的游乐场。 最初复制的步骤是什么? 在github中有一个很好的“fork”按钮,但出于明显的原因,我不能使用它 我如何跟踪fedorahosted回购协议到github回购协议的变化Git是否将现有的repo推送到新的、不同的远程repo服务器?,git,github,Git,Github,假设我在上有一个存储库,我想将它克隆到我在github的帐户中,除了fedorahosted上更“正式”的回购协议之外,还有我自己的游乐场。 最初复制的步骤是什么? 在github中有一个很好的“fork”按钮,但出于明显的原因,我不能使用它 我如何跟踪fedorahosted回购协议到github回购协议的变化 在github创建新的回购协议 将repo从fedorahosted克隆到本地计算机 git远程重命名源站上游 git远程添加源URL\u到\u GITHUB\u REPO git推送
git远程重命名源站上游
git远程添加源URL\u到\u GITHUB\u REPO
git推送原始主机
现在,您可以像处理任何其他github回购一样使用它。要从上游拉入修补程序,只需运行
git-pull-upstream-master和&git-push-origin-master
此问题的已删除答案中有一个有用的链接:
要点是
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
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
master:master
更改为source:destination
分支
如果要推送特定提交(分支),请执行以下操作:
git checkout -b new_branch
git log # Find the interesting hash
git reset 4b62bdc9087bf33cc01d0462bf16bbf396369c81 --hard
或者选择commit bygit cherry pick
以附加到现有头中git push https://github.com/user/example new_branch:master
如果要重新定基,请使用-f
进行强制推压(不推荐)。运行git reflog
查看更改历史记录您真的想将您的本地存储库(及其本地分支等)推送到新的远程服务器上,还是真的想在新的远程服务器上镜像旧的远程服务器(及其所有分支、标记等)?如果是后者,这里有一个很棒的博客 我强烈建议您阅读博客,了解一些非常重要的细节,但简短的版本如下: 在新目录中运行以下命令:
git clone --mirror git@example.com/upstream-repository.git
cd upstream-repository.git
git push --mirror git@example.com/new-location.git
git tag
git branch -a
git push origin --all
git push --tags
我也有同样的问题 在我的例子中,由于我在本地计算机中拥有原始存储库,所以我在一个新文件夹中创建了一个副本,没有任何隐藏文件(.git、.gitignore) 最后,我将.gitignore文件添加到新创建的文件夹中 然后,我从本地路径创建并添加了新的存储库(在我的例子中使用的是GitHub Desktop)。试试这个
git branch -a
git checkout branch-name
git fetch --tags
git clone --mirror git@example.com/upstream-repository.git
cd upstream-repository.git
git push --mirror git@example.com/new-location.git
git tag
git branch -a
git push origin --all
git push --tags
git remote rm origin
git remote add origin <url to NEW repo>
git remote rm origin
git remote add origin <url to NEW repo>
我使用设置url找到了一个简单易懂的解决方案:
cd
到本地计算机上的现有存储库中(如果尚未克隆,请先执行此操作)git远程设置url源https://github.com/user/example.git
git-push-u原始主机
如果您有现有的Git存储库:
cd rhq
git push https://github.com/user/example master:master
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 repo URL,即可指向新的repo:
git remote set-url origin [new repo URL]
示例:git远程设置url源git@bitbucket.org:蝙蝠侠/batmanRepoName.git
现在,推和拉与新的回购协议相关联
然后像这样正常推动:
git push -u origin master
以下是一种手动方式:
git Clone
/.git/config
$ git config -e
[core]
repositoryformatversion=0
filemode=false
裸=假
logallrefupdates=true
符号链接=假
ignorecase=true
[远程“源”]
url=
fetch=+refs/heads/*:refs/remotes/origin/*
[分行“主控”]
远程=原点
合并=参考/头/主
并更改遥控器(url选项)
[远程“源站”]
url=
fetch=+refs/heads/*:refs/remotes/origin/*
git Push
您也可以同时使用/没有理由重命名原始原点,只需将新的游乐场命名为其他名称即可。@tca:没有,但这是一个很强的惯例,
原点
指向规范的远程位置。在这种情况下,github的位置可能是规范的。也许我应该发布一个不同的问题,但我想你们正在讨论我想要什么。我想添加一个新的遥控器,而不是替换现有的遥控器,这样我可以继续从旧的存储库中提取,但可以将任何更改推送到新的存储库。@这不起作用,您可能应该打开一个新问题,但简言之,您可以使用命令git remote add
添加任意数量的遥控器。然后,您可以通过在git push
中显式声明远程按钮来推送到其中一个。例如,git push foobar master
将当前分支推送到远程foobar
上的master
。没有推送我的所有分支,只推送master。镜像的答案适用于所有分支我认为这是一个链接:这应该是公认的答案裸克隆和镜像推送的好处是什么?简单地添加并推送到另一个远程?是不是所有的分支都会被推,而不仅仅是cu