原文: 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. HDU 5813 Elegant Construction

    构造.从a[i]最小的开始放置,例如放置了a[p],那么还未放置的,还需要建边的那个点 需求量-1,然后把边连起来. #pragma comment(linker, "/STACK:1024 ...

  2. HDU 5798 Stabilization

    方法太厉害了....看了官方题解的做法....然后...想了很久很久才知道他想表达什么.... #pragma comment(linker, "/STACK:1024000000,1024 ...

  3. 用sqlyog远程连接LINUX系统的MYSQL出现错解决方法

    无法给远程连接的用户权限问题.结果这样子操作mysql库,即可解决.在本机登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost”改称'%' ...

  4. svn回滚

    有时会因为某些原因会错误提交某些文件: 1,官方版本库升级,自己的库代码也要跟着升级,但发现使用官方代码后有问题,代码需要回滚到可用的版本: 2,拷贝一个项目的代码到另外一个项目,把整个代码目录也拷贝 ...

  5. watch命令

    watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行.在Linux下,watch是周期性的执行下个 ...

  6. laravel使用多个数据库连接

    1.配置.env文件 DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=database_name DB_USERNAME= ...

  7. perl命令+关键字

    来源: http://www.cnblogs.com/itech/archive/2012/11/01/2749666.html http://www.garybeene.com/vb/tut-per ...

  8. redis - java 基本操作

    import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; im ...

  9. 8.5 sikuli 集成进eclipse 报错:can't be found on the disk

    运行提示can't be found on the disk

  10. Codeforces 704A Thor 队列模拟

    题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...