多账号配置

查询global配置

1
git config --global --list

设置或清空user配置

1
2
3
4
5
6
7
# 设置
git config --global user.name "test"
git config --global user.email "test@test.com"

# 清空
git config --global --unset user.name
git config --global --unset user.email

生成不同的ssh-key

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# github
ssh-keygen -t rsa -C "git@github.com" -f ~/.ssh/id_rsa_github

# gitlab
ssh-keygen -t rsa -C "git@gitlab.com" -f ~/.ssh/id_rsa_gitlab

# codeup
ssh-keygen -t rsa -C "git@codeup.aliyun.com" -f ~/.ssh/id_rsa_codeup

# 检查生成的密钥对
ls -l ~/.ssh

添加到ssh-agent信任列表

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# github
ssh-add ~/.ssh/id_rsa_github

# gitlab
ssh-add ~/.ssh/id_rsa_gitlab

# codeup
ssh-add ~/.ssh/id_rsa_codeup

# 检查ssh-agent信任列表
ssh-add -l

配置多个ssh-key

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
cat >> ~/.ssh/config <<EOF
# github
Host git@github.com
  HostName github.com
  Port 22
  User git
  IdentityFile ~/.ssh/id_rsa_github

# gitlab
Host git@gitlab.com
  HostName gitlab.com
  Port 22
  User git
  IdentityFile ~/.ssh/id_rsa_gitlab

# codeup
Host git@codeup.aliyun.com
  HostName codeup.aliyun.com
  Port 22
  User git
  IdentityFile ~/.ssh/id_rsa_codeup
EOF

测试

1
2
3
ssh -T git@gitlab.com
ssh -T git@github.com
ssh -T git@codeup.aliyun.com

日常使用命令

查看状态

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 查看代码仓库状态
git status

# 查看分支
git branch
git branch -v

# 查看tag
git tag

# 查看远程源信息
git remote show
git remote show origin

分支操作

提交

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# 添加文件
git add *

# 提交
git commit -m "add somefile"

# 推送分支
git push -u origin master
git push

# 推送tag
git push --tag