当前目录中项目的git配置文件为.git/config
从gerrit/github/gitlab下载后,要修改.git/config,增加[user]段落
同时如果有使用gerrit,要增加gitreview.username选项:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = ssh://10114292@gerrit.zte.com.cn:29418/paas/bdt/bdt-center
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[user]
name = 10114292
email = geng.liang5@zte.com.cn
[remote "gerrit"]
url = ssh://10114292@gerrit.zte.com.cn:29418/paas/bdt/bdt-center.git
fetch = +refs/heads/*:refs/remotes/gerrit/*
[gitreview]
username = 10114292
对gerrit,还需要创建和编辑.gitreview文件
[gerrit]
host=gerrit.zte.com.cn
port=29418
project=paas/bdt/bdt-center.git
username=10114292
修改前
root@a2440:~# git config -l
user.name=10114292
user.email=10114292@zte.com.cn
push.default=simple
root@a2440:/home/dockerws# cat ~/.gitconfig
[user]
name = 10114292
email = 10114292@zte.com.cn
[push]
default = simple
去除全局配置
git config --global --unset user.name
git config --global --unset user.email
root@a2440:/home/dockerws# cat ~/.gitconfig
[user]
[push]
default = simple
也可用命令:
git config --global push.default simple
创建github账号的key
root@a2440:~# ssh-keygen -C "hawkkingokey@163.com" -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa_github
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa_github.
Your public key has been saved in /root/.ssh/id_rsa_github.pub.
The key fingerprint is:
87:a6:59:18:4b:c3:ff:eb:29:85:42:f1:c6:cc:cb:5f hawkkingokey@163.com
The key's randomart image is:
+--[ RSA 2048]----+
| |
| .. |
| =* |
| ..**. |
| .ooSo. |
| .=+o. E |
| o. o.. |
| . .o |
| o+ |
+-----------------+
创建~/.ssh/config文件:
Host eta
HostName 10.62.100.147
Port 8000
User 10114292
IdentityFile ~/.ssh/id_rsa
Host zte
HostName gitlab.zte.com.cn
User 10114292
IdentityFile ~/.ssh/id_rsa
Host github
HostName github.com
User hawkkingokey
IdentityFile ~/.ssh/id_rsa_github
github项目管理
root@a2440:/home/gitworkspace# mkdir gittest
root@a2440:/home/gitworkspace# cd gittest/
root@a2440:/home/gitworkspace/gittest# ls
root@a2440:/home/gitworkspace/gittest# git init
Initialized empty Git repository in /home/gitworkspace/gittest/.git/
root@a2440:/home/gitworkspace/gittest# git config user.name hawkkingokey
root@a2440:/home/gitworkspace/gittest# git config user.email hawkkingokey@163.com
代理设置(可以跳过,使用系统的代理设置)
root@a2440:/home/gitworkspace/gittest# git config http.proxy proxysh.zte.com.cn:80
root@a2440:/home/gitworkspace/gittest# git config https.proxy proxysh.zte.com.cn:80
root@a2440:/home/gitworkspace/gittest# git config http.sslverify false
git config core.gitproxy proxysh.zte.com.cn:80
使用https协议clone github代码
root@a2440:/home/gitworkspace/gittest# git clone https://github.com/wiztools/rest-client.git
老项目的目录如果要提交代码,也需要配置用户和邮箱
root@a2440:/home/gitworkspace/eta-sh# git config user.name 10114292
root@a2440:/home/gitworkspace/eta-sh# git config user.email 10114292@zte.com.cn