git config

Github现在上传代码一般使用两种方式,一个是ssh,一个是https。

ssh由于安全问题逐步增加了各种限制,最开始我使用的时候还可以密码登录上传。后来就必须要密钥,再到现在需要走443端口(不确定是22端口被ban了,还是安全的问题,还是代理的问题,反正最终结局是用了443端口的ssh)。

https则需要使用gpg key,本机需要有管理gpg key的软件(好像?)。我在Mac上Push我的代码,先生成gpg key,然后按要求上传到github,就可以正常通过https push代码了。

Linux上gpg key的管理软件和git的配置有点说法,TBD。

git clone

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
git submodule init 
git submodule update
git submodule deinit --all

git rebase
git checkout

git reset --hard
git reset --soft

git cherrypick
git chechout

git branch -a # 查看所有分支
git branch -d <branch_name> # 删除分支

GitHub through proxy

Using SSH over the HTTPS port

背景:使用git上传GitHub一般需要科学上网。如果直接使用ssh的登陆方式可能会被代理服务器拒绝,因为ssh要访问22号端口。

关于一个用户使用多个git账户

1
2
3
4
5
git config --global user.name "公司"
git config --global user.email "公司邮箱"

git config user.name "私人"
git config user.email "私人邮箱"

给私人 GitHub 单独配 SSH key

因为 user.name/user.email 只影响 commit 作者信息,
真正 push 到哪里、用哪个账号认证,很多时候还取决于 SSH key 或 HTTPS 凭证。

如果你的私人仓库要 push 到 GitHub,最好单独配一把私人 key。

生成私人 key

1
ssh-keygen -t ed25519 -C "你的私人邮箱" -f ~/.ssh/id_ed25519_github_personal

配置 ~/.ssh/config

1
2
3
4
5
6
Host github-personal
HostName ssh.github.com
Port 443
User git
IdentityFile ~/.ssh/id_ed25519_github_personal
ProxyCommand none

已 clone 的仓库怎么改?

1
git remote set-url origin git@github-personal:user-name/repo.git