查看git所有配置項
$ git config -l
or
$ git config --list
全局配置用戶名郵箱
$ git config --global user.name "young"
$ git config --global user.email "young@163.com"
根據項目配置:
- 切換到項目目錄下,配置用戶名和密碼:
$ git config user.name "young"
$ git config user.email "young@163.com"
- 配置信息的存儲位置
對應的本地倉庫的.git文件中的config文件
在當前項目目錄下使用 cat .git/config,就可以看到配置文件內容
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = https://github.com/***/***.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
git config解析
user.email=leo@xxx.com
user.name=leo
core.ignorecase=false # 不許忽略文件名大小寫
core.autocrlf=input # 換行模式為 input,即提交時轉換為LF,檢出時不轉換
core.filemode=false # 不檢查文件權限
core.safecrlf=true # 拒絕提交包含混合換行符的文件
core.editor=vim
core.repositoryformatversion=0 # Internal variable identifying the repository format and layout version
core.bare=false # 默認不創建裸倉庫
core.logallrefupdates=true # log 所有 ref 的更新
core.precomposeunicode=true # Mac專用選項,開啟以便文件名兼容其他系統
push.default=simple # 只推送本地當前分支,且與上游分支名字一致
alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
pull.rebase=true # 強制開啟 rebase 模式
credential.helper store // 記住密碼
// 推薦配置
git config --global user.email “mtide@xxx.com"
git config --global user.name=mtide
sudo git config --system core.ignorecase false
sudo git config --system core.autocrlf input
sudo git config --system core.filemode false
sudo git config --system core.safecrlf true
sudo git config --system core.editor vim
sudo git config --system core.repositoryformatversion 0
sudo git config --system core.bare false
sudo git config --system core.logallrefupdates true
sudo git config --system core.precomposeunicode true
sudo git config --system push.default simple
sudo git config --system alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
sudo git config --system pull.rebase true
sudo git config credential.helper store // 記住密碼
配置記住密碼
[core]
autocrlf = true
excludesfile = C:\\Users\\lixinglong\\Documents\\gitignore_global.txt
[user]
name = leo
email = leo@***.cn
[credential]
helper = store // 這樣配置就會記住密碼了
git全局配置修改
$ git config -e --global
進入全局配置文件,擊字母i,進入編輯狀態,修改里面的內容。
連接遠程倉庫相關命令
// 查看git遠程庫信息
$ git remote -v
// 查看remote地址,遠程分支,還有本地分支與之相對應關系等一系列信息
$ git remote show origin
遠程倉庫的移除與重命名
如果想要重命名引用的名字可以運行 git remote rename
去修改一個遠程倉庫的簡寫名。 例如,想要將 pb
重命名為 paul
,可以用 git remote rename
這樣做:
$ git remote rename pb paul
$ git remote
origin
paul
值得注意的是這同樣也會修改你的遠程分支名字。 那些過去引用 pb/master
的現在會引用 paul/master
。
如果因為一些原因想要移除一個遠程倉庫 - 你已經從服務器上搬走了或不再想使用某一個特定的鏡像了,又或者某一個貢獻者不再貢獻了 - 可以使用 git remote rm
:
$ git remote rm paul
$ git remote
origin
參考文章:
https://blog.csdn.net/weixin_33768153/article/details/81026687
Git官方文檔-2.5 Git 基礎 - 遠程倉庫的使用