美文网首页
GIT切换远程地址仓库

GIT切换远程地址仓库

作者: SunYo | 来源:发表于2017-10-27 13:47 被阅读0次

有时候,我们想把一个项目从github切换到其他git服务器,免不了就要切换远程仓库地址。那这时候有什么办法解决呢?据目前自己的了解,有三种办法。
一、修改命令
git remote set-url origin url
二、先删后加
git remote rm origingit remote add origin git@github.com:sheng/demo.git
三、修改config文件
如果你的项目有加入版本控制,那可以到项目根目录下,查看隐藏文件夹, 发现.git文件夹,找到其中的config文件,就可以修改其中的git remote origin地址了。
切换完了之后我们发现无法提交代码,报错如下:

git push origin master
To git@github.com:qzmly100/repository-.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:qzmly100/repository-.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解决方案:
远程分支上存在本地分支中不存在的提交,往往是多人协作开发过程中遇到的问题,可以先fetch再merge,也就是pull,把远程分支上的提交合并到本地分支之后再push。先抓取并合并远程仓库全部内容(git pull origin master),再推送本地仓库数据(git push origin master)。
如果你确定远程分支上那些提交都不需要了,那么直接git push origin master -f,强行让本地分支覆盖远程分支


把本地仓库与远程仓库建立关联
git branch --set-upstream master origin/master

相关文章

  • 常见 Git 命令(持续记录)

    仓库相关 查看远程仓库地址:git remote -v 切换远程仓库地址:直接切换:git remote set-...

  • tip02

    git切换远程仓库地址 1.查询现在的远程仓库名称 git remote 2.查询现在的远程仓库名称和地址 ...

  • git 切换远程仓库地址

    1、切换远程仓库地址:方式一:修改远程仓库地址 【git remote set-url origin URL】 更...

  • git 切换远程仓库地址

    1、切换远程仓库地址:方式一:修改远程仓库地址 【git remote set-url origin URL】 更...

  • git 切换远程仓库地址

    切换远程仓库地址(相同目录下) 方式一:修改远程仓库地址【git remote set-url origin UR...

  • Git切换远程仓库地址

    麦子时光 有时候,我们用着用着git,运维突然说要迁移git地址。我们开发人员也是只能配合。 那这时候有什么办法解...

  • Git 切换远程仓库地址

    最近后台git地址变更,本地需要修改远程仓库地址 记录一下 origin 是默认的远程版本库名称 先查看远程地址...

  • GIT切换远程地址仓库

    有时候,我们想把一个项目从github切换到其他git服务器,免不了就要切换远程仓库地址。那这时候有什么办法解决呢...

  • Git切换远程仓库地址

    由于公司的Git服务机器搬迁,导致域名变动,所以不得不更改当前已有的项目的远程仓库地址。 首先使用git命令git...

  • GIT切换远程仓库地址

    一、修改命令 二、先删后加 三、修改config文件 如果你的项目有加入版本控制,那可以到项目根目录下,查看隐藏文...

网友评论

      本文标题:GIT切换远程地址仓库

      本文链接:https://www.haomeiwen.com/subject/pabrpxtx.html