git多用户配置多server配置

有时我们可能会有多个git帐号连接到多个不同的server,或者相同的server.
Git共有三个级别的config文件,分别是system、global和local。在当前环境中,分别对应%GitPath%\mingw64\etc\gitconfig文件、$home\.gitconfig文件和%RepoPath%\.git\config文件。
其中%GitPath%为Git的安装路径,%RepoPath%为某仓库的本地路径。所以system配置整个系统只有一个,global配置每个账户只有一个,而local配置和git仓库的数目相同,并且只有在仓库目录才能看到该配置。

首先查看本地配置:
打开git bash,输入: git config --list
输出大概如下:
$ git config --list
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
rebase.autosquash=true
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
credential.helper=manager
core.editor='C:\Program Files (x86)\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin
user.name=cdpush
[email protected]
gui.recentrepo=D:/YPP-Works
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
[email protected]:ekinj/yyp-tsbe.git
remote.gitee.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
remote.origin.url=git@jiangyequn:jiangyequn/ypp-tsbe.git
remote.origin.fetch=+refs/heads/*:refs/remotes/ypp-tdbe/

最重要的一步的是要在C:\Users\jiangyequn\.ssh目录下添加一个config文件, 文件内容格式如下

Host gitlab.domain.cn jiangyequn  //git域名map
User jiangyequn   //git账号
HostName gitlab.domain.cn         //git服务器
IdentityFile ~/.ssh/Ekin_YPP_Account_rsa/id_rsa // 用户的private key


Host gitlab.domain.cn cdpush
User cdpush
HostName gitlab.domain.cn
IdentityFile ~/.ssh/cdpush

Host gitee.com gitee.com
User [email protected]
HostName gitee.com
IdentityFile ~/.ssh/xxxxx/id_rsa

参考: https://www.jianshu.com/p/0ad3d88c51f4
 

猜你喜欢

转载自blog.csdn.net/kielin/article/details/81484113