git 代理配置

February 03, 2020

因为疫情关系开始在家办公。之前使用的 iOA NGN 版本,拉取内网代码需要额外设置代理。 现在使用 VPN 版本拉取代码会报错,需要取消代理。

全局设置代理

git config --global http.proxy 'socks5://127.0.0.1:8080'
git config --global https.proxy http://127.0.0.1:8080
# 取消代理
git config --global --unset http.http://github.com.proxy
git config --global --unset http.https://github.com.proxy

对指定网址设置代理

git config --global http.http://github.com.proxy http://127.0.0.1:8080
git config --global http.https://github.com.proxy http://127.0.0.1:8080

// 取消代理
git config --global --unset http.http://github.com.proxy
git config --global --unset http.https://github.com.proxy

git config 的作用域

--local 对当前仓库进行设置
--global 对当前登录用户进行全局设置
--system 对系统中的所有用户进行设置

空项目设置

Git global setup

git config --global user.name "name"
git config --global user.email "name@gmail.com"

Create a new repository

git clone git@github.com:name/repo-demo.git
cd repo-demo
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Push an existing folder

cd existing_folder
git init
git remote add origin git@github.com:name/repo-demo.git
git add .
git commit -m "Initial commit"
git push -u origin master

Push an existing Git repository

cd existing_repo
git remote rename origin old-origin
git remote add origin git@github.com:name/repo-demo.git
git push -u origin --all
git push -u origin --tags

FAQ

执行取消报错时, 可以直接编辑 .gitconfig 文件, 删除对应配置信息


Profile picture

Written by xiaohai who lives and works in ShenZhen, building useful things.