git配置

217 阅读3分钟

配置 Git

设置用户名和邮箱

SHELL
git config --global user.name "mlemontx"
git config --global user.email "mlemontx@example.com"

查看配置信息

SHELL
git config -l
git config --list

配置代理

SHELL
git config --global http.proxy  'http://127.0.0.1:7890' 
git config --global https.proxy 'http://127.0.0.1:7890'

取消代理

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

查看代理

SHELL
git config --global --get http.proxy
git config --global --get https.proxy

移除凭证

SHELL
git config --global --unset credential.helper

出现以下错误可以尝试使用该命令(拉取代码时输入用户名和 token):

SHELL
remote: repositorysitory not found.

获取远程仓库

克隆远程仓库

SHELL
git clone https://github.com/username/repository.git

管理远程仓库

添加远程仓库

git remote add 命令采用两个参数:

  • 远程名称(例如 origin
  • 远程 URL(例如 https://github.com/username/repository.git
SHELL
git remote add origin https://github.com/username/repository.git

查看当前的远程库

SHELL
git remote -v

更改远程仓库的 URL

SHELL
git remote set-url origin https://github.com/username/new_repository.git

重命名远程仓库

git remote rename 命令采用两个参数:

  • 现有远程名称(例如 origin
  • 远程的新名称(例如 destination
SHELL
git remote rename origin destination

删除远程仓库

SHELL
git remote remove origin
git remove rm origin

管理分支

签出分支

SHELL
git checkout branchName

查看分支

查看本地已经存在的分支(当前分支会用*标记)

SHELL
git branch

查看本地和远程的所有分支(remotes/ 开头表示远程分支):

SHELL
git branch -a

本地分支关联远程分支

SHELL
git branch --set-upstream-to=origin/remote_branch your_branch

版本控制

删除本地缓存

SHELL
git rm -r --cached .

重新添加

SHELL
git add .

查看状态

SHELL
git status

撤回

已提交撤回

  1. 查看历史提交日志 git log
  2. 通过 git reset HEAD^^ 回退两个版本

ERROR

TXT
remote: Support for password authentication was removed on August 13, 2021. Please use a personal acce

配置 Git

设置用户名和邮箱

SHELL
git config --global user.name "mlemontx"
git config --global user.email "mlemontx@example.com"

查看配置信息

SHELL
git config -l
git config --list

配置代理

SHELL
git config --global http.proxy  'http://127.0.0.1:7890' 
git config --global https.proxy 'http://127.0.0.1:7890'

取消代理

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

查看代理

SHELL
git config --global --get http.proxy
git config --global --get https.proxy

移除凭证

SHELL
git config --global --unset credential.helper

出现以下错误可以尝试使用该命令(拉取代码时输入用户名和 token):

SHELL
remote: repositorysitory not found.

获取远程仓库

克隆远程仓库

SHELL
git clone https://github.com/username/repository.git

管理远程仓库

添加远程仓库

git remote add 命令采用两个参数:

  • 远程名称(例如 origin
  • 远程 URL(例如 https://github.com/username/repository.git
SHELL
git remote add origin https://github.com/username/repository.git

查看当前的远程库

SHELL
git remote -v

更改远程仓库的 URL

SHELL
git remote set-url origin https://github.com/username/new_repository.git

重命名远程仓库

git remote rename 命令采用两个参数:

  • 现有远程名称(例如 origin
  • 远程的新名称(例如 destination
SHELL
git remote rename origin destination

删除远程仓库

SHELL
git remote remove origin
git remove rm origin

管理分支

签出分支

SHELL
git checkout branchName

查看分支

查看本地已经存在的分支(当前分支会用*标记)

SHELL
git branch

查看本地和远程的所有分支(remotes/ 开头表示远程分支):

SHELL
git branch -a

本地分支关联远程分支

SHELL
git branch --set-upstream-to=origin/remote_branch your_branch

版本控制

删除本地缓存

SHELL
git rm -r --cached .

重新添加

SHELL
git add .

查看状态

SHELL
git status

撤回

已提交撤回

  1. 查看历史提交日志 git log
  2. 通过 git reset HEAD^^ 回退两个版本

ERROR

TXT
remote: Support for password authentication was removed on August 13, 2021. Please use a personal acce