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

Changing a remote's URL

 

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.

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

Changing a remote's URL的更多相关文章

  1. git 获取 remote 的 url

    git 获取 remote 的 url git ls-remote --get-url [remote] 例如: git ls-remote --get-url origin  

  2. Command failed: git -c core.longpaths=true config --get remote.origin.url

    「Unable to Connect to GitHub.com For Cloning」 Error: Command failed: git -c core.longpaths=true conf ...

  3. 修改Git远程地址 git config remote.origin.url "https://..."

    仓库管理: 添加或指定远程仓库地址 git remote set-url origin "https://..." git config remote.origin.url &qu ...

  4. git url ssh和https相互切换

    Changing a remote's URL The git remote set-url command changes an existing remote repository URL. Ti ...

  5. git配置ssh(github)

    [参考官方文档] SSH keys are a way to identify trusted computers, without involving passwords. The steps be ...

  6. Android ADT离线更新办法

    Troubleshooting ADT Installation If you are having trouble downloading the ADT plugin after followin ...

  7. NodeJS+Express+MySQL开发小记(2):服务器部署

    http://borninsummer.com/2015/06/17/notes-on-developing-nodejs-webapp/ NodeJS+Express+MySQL开发小记(1)里讲过 ...

  8. github push403错误的处理

    如果没有什么别的问题的话,推荐使用SSH的方式.请参考:http://stackoverflow.com/questions/7438313/pushing-to-git-returning-erro ...

  9. 【ASK】git使用中出现Permission denied (publickey).

    好久没有用git了,今天突然执行了一下 $git submodule update --init --recursive =============================== 结果出现如下提 ...

随机推荐

  1. js 放置 cookie、获取 cookie、删除 cookie

    这块TM的删不掉 代码如下: // 自定义 js cookies var mycookie = { // 放置 set : function(name,value){ var Days = 1; // ...

  2. VMware 虚拟机(linux)增加根目录磁盘空间

    今天查看学校的监控报修系统,不能访问了!!!系统运行很慢,用top命令查看发现内存使用率90%,用"df -h ”查看“/”目录使用率已达到80%,导致系统运行很慢.我用以下方法扩大根目录磁 ...

  3. 理解VMware虚拟机下网络连接的三种模式(如何配置虚拟机上网)

    很多朋友都用vmware来测试不同的系统,我结合自己的经验谈一下对网络设置的理解,不对的地方请指正. bridge:这种方式最简单,直接将虚拟网卡桥接到一个物理网卡上面,和linux下一个网卡 绑定两 ...

  4. 样式的操作-不同浏览器加载不同的css文件

    ———————————————————— <script type="text/javascript">            //body加载事件监听函数       ...

  5. SQL Server 存储过程进行分页查询

    CREATE PROCEDURE prcPageResult -- 获得某一页的数据 -- @currPage INT = 1 , --当前页页码 (即Top currPage) @showColum ...

  6. LeetCode OJ 217.Contains Duplicate

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  7. PHP:class static

    简介 static关键词的一种常见用途是,当类的某个变量$var被定义为static时,那么$var就是类的变量. 这意味着:1,该类的任意一个实例对其进行修改,在该类的其它实例中访问到的是修改后的变 ...

  8. PHP处理密码的几种方式【转载】

    转自:http://www.3lian.com/edu/2015/08-01/235322.html 在使用PHP开发Web应用的中,很多的应用都会要求用户注册,而注册的时候就需要我们对用户的信息进行 ...

  9. TortoiseGit保存用户名密码的方法

    方法一: 设置 -> git 编辑本地 .git/config 增加 1 [credential]    2     helper = store 保存,输入一次密码后第二次就会记住密码了 方法 ...

  10. table详解

    1.tr 元素定义表格行,th 元素定义表头,td 元素定义表格单元. tr内是th还是td可由自己定义,th,td可存在于任一行,th与td的区别在与th字体更粗 2.定义一个table默认有bor ...