[英]How do I push my existing repo to a fork of another repo?
I have been working on a project, and I maintain a git repo for the project on GitHub.我一直在做一个项目,我为 GitHub 上的项目维护了一个 git 存储库。
However, my workplace has now created a repository for this project and asked me to send a PR there.但是,我的工作场所现在已经为这个项目创建了一个存储库,并要求我在那里发送一个 PR。 I have forked this new repository.
我已经分叉了这个新的存储库。
My initial instinct was to clone this fork and copy paste all the files from my original project, and push.我最初的直觉是克隆这个 fork 并复制粘贴我原始项目中的所有文件,然后推送。 But doing so, I will lose all my commits.
但是这样做,我将失去所有的提交。
Is there a better way?有没有更好的办法? Like to push my existing repo to this fork?
喜欢将我现有的回购推送到这个分叉?
Depending if the repositories have same history you can just add new origin.根据存储库是否具有相同的历史记录,您可以添加新的来源。
Firstly check current git remote:首先检查当前的 git 遥控器:
git remote -v
origin git@my-old-git.com:repo/path/repo.git (fetch)
origin git@my-old-git.com:repo/path/repo.git (push)
Then add new remote然后添加新的遥控器
git remote add origin2 git@my-new-git.com:repo/path/repo.git
Now you can push with现在你可以用
git push origin2 my-branch
First, clone your new forked repo.首先,克隆您的新分叉存储库。
Then add your previous repo as a remote然后将您以前的仓库添加为远程
git remote add old-origin <path>
git fetch old-origin
Then pull your previous repo commit然后拉你以前的回购提交
git pull old-origin master --rebase
After that push to your new forked repo之后推送到您的新分叉回购
git push origin master
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.