Github 使用介绍
相关网站
基础使用
配置 sshkey
参考 SSH 常用命令
ssh-keygen -t rsa -C "邮箱"
复制 ~\.ssh\id_rsa.pub 文件中的内容,登录 Github –> Account Setting –> SSH-KEY –> Add SSH-KEY –> 粘贴id_rsa.pub中的内容
ssh -T git@github.com
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
说明配置成功,可以连接上 Github
SSH/PGP key 地址
curl https://github.com/<username>.keys | tee -a ~/.ssh/authorized_keys
curl https://github.com/xiexianbin.keys
curl https://api.github.com/users/xiexianbin/keys
# GPG 签名公钥 (GPG Signing Keys),用于获取用户上传到 GitHub 的 GPG 密钥,这些密钥通常用于对 Git 提交进行签名,以验证身份
curl https://github.com/<username>.gpg
curl https://github.com/<username>.gpg | gpg --import
curl https://github.com/xiexianbin.gpg
curl https://github.com/xiexianbin.gpg | gpg --import
# GitHub REST API 用户 GPG 公钥列表
https://api.github.com/users/<username>/gpg_keys
| 地址类型 |
格式 |
返回格式 |
用途 |
| SSH 公钥 |
https://github.com/<username>.keys |
纯文本 |
快速获取 SSH 公钥(您提到的)。 |
| GPG 公钥 |
https://github.com/<username>.gpg |
纯文本 |
快速获取 GPG 签名公钥。 |
| API (SSH) |
https://api.github.com/users/<username>/keys |
JSON |
获取 SSH 公钥的结构化详细列表。 |
| API (GPG) |
https://api.github.com/users/<username>/gpg_keys |
JSON |
获取 GPG 公钥的结构化详细列表。 |
请注意: 纯文本的 .keys 和 .gpg 格式更适合在 Shell 脚本中快速获取公钥并追加到 authorized_keys 文件等场景。API 格式则更适合用于需要结构化数据和更多详细信息的应用程序。
Fork 仓库
点击仓库右上角的Fork后,选择需要放到的org即可。
保证代码同步
git clone 这个 fork 的项目
git clone <fork url>
git remote add <name> <ori url>
# 更新 "指定" remote 底下的分支
git fetch <name> <branch>
# 更新多个 remote 底下的分支
git remote update
## 或者
git fetch --all
# 保持同步
git pull --rebase <remote> <branch>
## 等同于以下两条命令
git fetch <remote> <branch>
git rebase <remote>/<branch>
pull request
Github上的许多开源项目使用pull request进行代码review和讨论。
pull request有 2 种类型:
- 对一个
forked仓库进行pull request
- 对一个仓库里的分支进行
pull request
issue
github使用issue追踪需求和修复 bug。
创建分支
贡献者创建一个自己的新分支,在该分支上进行操作,最后通过pull request方式合并到主分支上。命令如下:
git checkout -b feature_x
git push --set-upstream origin <分支名>
Git commit 规范
Git commit 规范
创建 github app
到 https://github.com/settings/applications/new 注册 Github APP,并获取和配置
- OAuth2 client ID
- OAuth2 client Secret
- callback url
- 登录的用户,需要在某个组织中,示例为 beehat 组织,test teams
CI
Github 第三方扩展