原文: 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. IP子网掩码格式转换

    def exchange_maskint(mask_int): bin_arr = [' for i in range(32)] for i in range(mask_int): bin_arr[i ...

  2. cocoaPods的安装方法

    1.打开终端 2.先升级Gem sudo gem update --system 3.切换cocoapods的数据源 [先删除,再添加,查看] gem sources --remove https:/ ...

  3. HADOOP与ORACLE关联

    安装Oracle和Oracle大数据连接器/OLH,尝试把HDFS中的数据文件装载到Oracle中的表 http://f.dataguru.cn/thread-460110-1-1.html 文档讲述 ...

  4. 使用CSS灵活的盒子

    CSS3灵活的盒子,或flexbox,是一个布局模式提供页面上的元素的安排这样的元素表现可以预见当页面布局必须适应不同屏幕大小和不同的显示设备.对于许多应用程序,灵活的块盒模型提供了一个改进模型,它不 ...

  5. Thrift项目Server端开发流程

    Thrift项目Server端开发流程 首先,先了解工程中所有包的功能(见下图) 该图为用户中心项目的目录结构,以下依次介绍. 1.     src/main/java com.framework:该 ...

  6. H5的新应用-在地图上标识附近加油站的地址

    ------------------------ <style type="text/css">          html{height:100%}         ...

  7. javascript中的throttle和debounce

    throttle 我们这里说的throttle就是函数节流的意思.再说的通俗一点就是函数调用的频度控制器,是连续执行时间间隔控制.主要应用的场景比如: 1.鼠标移动,mousemove 事件2.DOM ...

  8. js 交换表单中值

    <html> <head> <meta charset="utf-8" /> <script type="text/javasc ...

  9. nefu 197 关键字检索(kmp算法)

    Description 在信息检索系统中一个很重要的环节就是关键字符串的查找,从而很多对自己有用的信息.给你一个很长的一段文字, 和一个关键信息字符串,现在要你判断这段文字里面是否有关键字符串. In ...

  10. 去掉uitableveiw多余的分割线

    UIView *v = [[UIView alloc] initWithFrame:CGRectZero]; [_tableView setTableFooterView:v];