原文: https://help.github.com/articles/changing-a-remote-s-url/

Changing a remote's URL

  • MAC
  • WINDOWS
  • LINUX

The git remote set-url command changes an existing remote repository URL.

Tip: For information on the difference between HTTPS and SSH URLs, see "Which remote URL should I use?"

The git remote set-url command takes two arguments:

  • An existing remote name. For example, origin or upstream are two common choices.
  • A new URL for the remote. For example:

    • If you're updating to use HTTPS, your URL might look like:

      https://github.com/USERNAME/OTHERREPOSITORY.git
      
    • If you're updating to use SSH, your URL might look like:

      git@github.com:USERNAME/OTHERREPOSITORY.git
      

Switching remote URLs from SSH to HTTPS

  1. Open Git Bash.

  2. Change the current working directory to your local project.

  3. List your existing remotes in order to get the name of the remote you want to change.

    git remote -v
    origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
    origin  git@github.com:USERNAME/REPOSITORY.git (push)
    
  4. Change your remote's URL from SSH to HTTPS with the git remote set-url command.

    git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git
    
  5. Verify that the remote URL has changed.

    git remote -v
    # Verify new remote URL
    origin  https://github.com/USERNAME/OTHERREPOSITORY.git (fetch)
    origin  https://github.com/USERNAME/OTHERREPOSITORY.git (push)
    

The next time you git fetchgit pull, or git push to the remote repository, you'll be asked for your GitHub username and password.

  • If you have two-factor authentication enabled, you must create a personal access token to use instead of your GitHub password.
  • You can use a credential helper so Git will remember your GitHub username and password every time it talks to GitHub.

Switching remote URLs from HTTPS to SSH

  1. Open Git Bash.

  2. Change the current working directory to your local project.

  3. List your existing remotes in order to get the name of the remote you want to change.

    git remote -v
    origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
    origin  https://github.com/USERNAME/REPOSITORY.git (push)
    
  4. Change your remote's URL from HTTPS to SSH with the git remote set-url command.

    git remote set-url origin git@github.com:USERNAME/OTHERREPOSITORY.git
    
  5. Verify that the remote URL has changed.

    git remote -v
    # Verify new remote URL
    origin  git@github.com:USERNAME/OTHERREPOSITORY.git (fetch)
    origin  git@github.com:USERNAME/OTHERREPOSITORY.git (push)
    

Troubleshooting

You may encounter these errors when trying to changing a remote.

No such remote '[name]'

This error means that the remote you tried to change doesn't exist:

git remote set-url sofake https://github.com/octocat/Spoon-Knife
fatal: No such remote 'sofake'

Check that you've correctly typed the remote name.

Further reading

转载于:https://www.cnblogs.com/oxspirt/p/6063507.html

Changing a remote's URL相关推荐

  1. git服务器 修改url,如何更改Git Remote的URL

    Git Remote是一个指针,它指向通常托管在远程服务器上的存储库的另一个副本. 在某些情况下,例如将远程存储库迁移到另一个主机时,您需要更改远程URL. 本指南介绍了如何更改Git遥控器的URL. ...

  2. 为Eclipse安装安卓开发插件ADT

    ADT下载地址:http://dl.google.com/android/ADT-20.0.3.zip 有关ADT的介绍及安装环境要求:http://developer.android.com/too ...

  3. 解决fatal: No remote repository specified. Please, specify either a URL...

    今天在电脑上用Git pull命令来更新本地项目,突然发现出现如标题的错误: [plain] view plaincopyprint? user ~/c/quhao$git pull fatal: N ...

  4. linux篡改url命令,在Linux中更改Git远程URL(Git Remote URL)的方法

    本文说明了如何更改Git远程的URL,在Linux平台中已测试成功.Git remote是一个指针,它指向通常托管在远程服务器上的存储库的另一个副本,在某些情况下,例如当远程存储库迁移到另一个主机时, ...

  5. git remote添加其他SSH端口

    本文翻译自:git remote add with other SSH port 在Git中,当主机使用不同的SSH端口时,如何添加远程源服务器? git remote add origin ssh: ...

  6. 如何更改远程Git存储库的URI(URL)?

    我在硬盘驱动器(本地)上克隆的USB密钥上有一个回购(来源). 我将"起源"移至NAS并成功测试了从此处克隆它的过程. 我想知道是否可以在"本地"设置中更改&q ...

  7. 如何确定最初克隆本地Git存储库的URL?

    几天前我从GitHub上撤了一个项目. 我已经发现GitHub上有几个叉子,我忽略了我最初采用的那个. 如何确定我拉出的哪个叉子? #1楼 打印任意命名的远程提取URL: git remote -v ...

  8. 解决github push错误The requested URL returned error: 403 Forbidden while accessing(转)

    github push错误: git push error: The requested URL returned error: 403 Forbidden while accessing https ...

  9. fatal: unable to access : The requested URL returned error: 403

    错误提示如下 C:\Users\AllenIverson\Desktop\gitbook-test>git push -u gitbook master remote: Forbidden fa ...

最新文章

  1. python重复元素判定编程_从零开始学Python编程四:条件判断与循环
  2. Eclipse启动出现“Failed to create the Java Virtual Machine”错误
  3. python实现并发http_python 2.7 如何实现http post多并发?
  4. lucene 入门整理
  5. Activiti中的安全脚本如何工作
  6. 重磅!“东方理工大学”来了!
  7. uwsgi怎么通过浏览器访问某个脚本_4个Shell小技巧帮你提高机器学习效率:写好脚本,事半功倍...
  8. 122 - Trees on the level(模拟内存池解法)
  9. linux系列之-—01 shell编程笔记
  10. IDEA + Spring boot devtools 热部署 与 多实例启动
  11. 经典而常用的配乐和背景音乐合集(下)
  12. 我很高兴,很欣慰:)
  13. 诗词乱拼 zz from smth.org
  14. vue项目使用iconfont(本地下载、彩色icon)
  15. Excel下拉菜单如何制作?
  16. 开水果蔬菜超市利润大吗?
  17. 面试.net资深程序员的前5分钟
  18. IDEA2016 license server 激活
  19. 计算机中全半角转换是干什么的,全角半角切换快捷键(电脑全角和半角怎么切换)...
  20. 没有躲过的坑--有if就要有else(一定成对)

热门文章

  1. 谷歌Chrome浏览器开发者工具教程—基础功能篇
  2. 数值分析matlab实验报告,数值分析第一次作业matlab实验报告.doc
  3. mysql教程日志_MySQL日志
  4. python数据可视化第三方库有哪些_数据可视化!看看程序员大佬都推荐的几大Python库...
  5. 目标检测(十七)--PVANet
  6. .net 本地文件管理 代码_Gitee 在线解决代码冲突上线,解决冲突不再需要 Git 命令...
  7. 适配器模式的原理与实现
  8. sbt命令行常用命令
  9. clickhouse入门与安装
  10. Hbase数据模型入门