月度归档:2015年01月

git remote url 从https到ssh,从ssh到https

git remote set-url 命令可以改变一个代码库的url.
git remote set-url 命令可以接受两个参数:
The git remote set-url command takes two arguments:

  • 一个远程名字,比如: origin
  • 远程的url,比如
    • https://github.com/USERNAME/REPOSITORY_2.git 如果你想改为使用 HTTPS
    • git@github.com:USER/REPOSITORY_2.git 如果你想改为使用SSH

远端url从ssh改成https

  1. 打开终端 (Mac 和 Linux) 或者命令行 (Windows).
  2. cd到你的目录里.
  3. 显示现在的远程url.
    git remote -v
    origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
    origin  git@github.com:USERNAME/REPOSITORY.git (push)
    
  4. 使用remote set-url 命令切换url.
    git remote set-url origin https://github.com/USERNAME/REPOSITORY_2.git
    
  5. 验证一下是不是已经改变.
    git remote -v
    origin  https://github.com/USERNAME/REPOSITORY2.git (fetch)
    origin  https://github.com/USERNAME/REPOSITORY2.git (push)
    

    下一次你使用 git fetch, git pull, 或者 git push 命令的时候,会提示你输入用户名和密码。

Switching remote URLs from HTTPS to SSH

  1. 打开终端 (Mac 和 Linux) 或者命令行 (Windows).
  2. cd到你的目录里.
  3. 显示现在的远程url.

    git remote -v
    origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
    origin  https://github.com/USERNAME/REPOSITORY.git (push)
    
  4. 使用remote set-url 命令切换url.
    git remote set-url origin git@github.com:USERNAME/REPOSITORY2.git
    
  5. 验证一下是不是已经改变.
    git remote -v
    origin  git@github.com:USERNAME/REPOSITORY2.git (fetch)
    origin  git@github.com:USERNAME/REPOSITORY2.git (push)
    

Git 设置代理

可以使用命令行设置,也可以通过配置文件设置。

使用命令行

设置代理

git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
git config --global https.proxy https://proxyuser:proxypwd@proxy.server.com:8080
  • proxyuser 是你代理服务器的用户名
  • proxypwd 是你代理服务器用户名的密码
  • proxy.server.com 是你代理服务器的地址,直接写ip也可以
  • 8080 代理服务器的端口

删除代理

git config --global --unset http.proxy
git config --global --unset https.proxy

使用配置文件

在你的用户的根目录下,有个文件.gitconfig,可以通过更改这个文件来设置代理
增加以下代码:

[http]
    proxy = http://username:password@proxy.at.your.org:8080

mac

mac.gitconfig

ubuntu

ubuntu.gitconfig

windows

image 1420765034