简体   繁体   English

将本地git推送到新的远程

[英]Push local git to new remote

I have 2 git repositories set up, and I did a lot of coding in 1. Someone else grabbed the code to make changes to the code, but never pushed them up. 我设置了2个git存储库,并在1个代码中做了很多编码。其他人抓住了代码以对代码进行更改,但从未提出来。

The changes are now so large, I want to push it to an entirely new repository. 现在的更改是如此之大,我想将其推送到一个全新的存储库中。 I have their computer, and I tried to git remote rm origin . 我有他们的电脑,我试图git remote rm origin Then i tried git remote add origin <url> , but it gives the following error 然后我尝试了git remote add origin <url> ,但是它给出了以下错误

fatal: remote origin already exists. 致命:远程来源已经存在。

Is there a way to push this to a new origin, and have it entirely forget about the first(like, not even remember it's a branch of the first)? 有没有办法将其推向新的起点,并完全忘记第一个(例如,甚至不记得它是第一个的分支)?

I am not clear with your problem, still giving it a try. 我不清楚您的问题,还是尝试一下。 You might not need to remove origin . 您可能不需要删除origin Instead add a new one with some other name like original 而是添加一个具有其他名称(例如原始名称)的新名称

git remote add original <url>
git push -u original <branch_name>

Edit To view all the remotes use git remote -v . 编辑要查看所有遥控器,请使用git remote -v Check the remote list before adding a new remote. 在添加新的遥控器之前,请检查遥控器列表。 It will tell you which remote_name is available and which is not. 它将告诉您哪个remote_name可用,哪些不可用。

Edit2 EDIT2

If you have already added a 'git origin' to your .git configuration . 如果您已经在.git configuration添加了“ git origin”。 You can change the remote origin URL in your git config with the following line: 您可以使用以下行在git配置中更改远程来源URL

git remote set-url origin git@github.com:{user}/{project}.git

To remove a remote, use git remote remove <name> you can see more details by git help remote 要删除远程,请使用git remote remove <name>您可以通过git help remote查看更多详细信息

Also, I believe changing the meaning of origin is not a best practice, if you just need to temporarily push to a new remote, just add it with another name, such as: git remote add <name> <url> 另外,我认为更改origin的含义不是最佳做法,如果您只是需要临时推送到新的远程服务器,只需添加另一个名称即可,例如: git remote add <name> <url>

When you add a new remote you can see it with git remote or git remote -v to see url details. 添加新的remote ,可以使用git remotegit remote -v查看它,以查看URL详细信息。

Then using git push -u <your-new-remote> would push your repo to <your-new-remote> 然后使用git push -u <your-new-remote>会将您的仓库推送到<your-new-remote>

EDIT: 编辑:

My fault, I didn't notice that git remote rm <name> is also usable since it did not appear in git help remote 我的错,我没有注意到git remote rm <name>也可用,因为它没有出现在git help remote

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 推送新的本地项目以存在远程Git - Push new local project to exsiting remote Git git - 不推送本地更改,而是在新分支中接收远程更改 - git - do not push local changes, but receive remote changes in new branch 将本地新的Git存储库作为分支推送到现有的远程存储库? - Push local new Git repo to existing remote repo as branch? Git将新的本地分支推送到远程,而无需指定名称 - Git push new local branch to remote, without having to specify name 将未提交的本地 git 更改推送到新的远程分叉 - Push uncommitted local git changes to a new remote fork 将本地 Git 回购推送到新的远程,包括所有分支和标签 - Push local Git repo to new remote including all branches and tags git new本地分支创建,然后推送远程分支(new remote),然后使用JGIT进行上游设置 - git new local branch creation then push remote branch(new remote) and then set upstream using JGIT 如何将已建立的本地git存储库链接到新的远程存储库并将所有文件推送到远程? - How do I link an already established local git repository to a new remote repository and push all files to remote? Visual Studio Code - 连接到远程 Git 存储库并将本地文件推送到新的远程存储库 - Visual Studio Code - Connect to a remote Git repository and PUSH local files to a new remote repository Git“强制推送”从新的本地仓库到远程,但保持远程提交历史记录 - Git “force push” from new local repo to remote, but keeping remote commit history
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM