用git的那点事
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 | git submodule init |
GitHub through proxy
背景:使用git上传GitHub一般需要科学上网。如果直接使用ssh的登陆方式可能会被代理服务器拒绝,因为ssh要访问22号端口。
关于一个用户使用多个git账户
1 | git config --global user.name "公司" |
给私人 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 | Host github-personal |
已 clone 的仓库怎么改?
1 | git remote set-url origin git@github-personal:user-name/repo.git |
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.