1,安装git
查看mac上是否已安装git
git --version
如果没有,可以通过安装Xcode后配置,或者通过 xcode-select --install 安装。具体安装方法请百度。
2,创建github账号
创建github的邮箱后面会用到
3,创建ssh,配置本地git
参考:Git - 初次运行 Git 前的配置 (git-scm.com)
设置username和email(github每次commit都会记录他们)
git config --global user.name "xxx"
git config --global user.email xxx@xxx.com //注册github的邮箱
如果要查看配置,使用如下命令
git config --list
通过终端命令创建ssh key
xxx@xxx ~ % ssh-keygen -t rsa -C xxx@xxx.com //注册github的邮箱
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/xxx/.ssh/id_rsa): //此处直接回车即可
Created directory '/Users/xxx/.ssh'.
Enter passphrase (empty for no passphrase): //设置一个密码
Enter same passphrase again:
Your identification has been saved in /Users/xxx/.ssh/id_rsa
Your public key has been saved in /Users/xxx/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:xxx/xxxxxxx xxx@xxx.com
The key's randomart image is:
+---[RSA 3072]----+
| o|
| o.|
| o +|
| . . o.|
| o + .+..o|
| . oo o**|
| . ..+*oo|
| . ..+ +oo**|
| .o*==.=.==|
+----[SHA256]-----+
xxx@xxx ~ %
终端查看.ssh/id_rsa.pub
文件
open /Users/xxx/.ssh/id_rsa.pub
4,设置github
添加ssh
title可以随便填,key是第三步.ssh/id_rsa.pub文件里的密钥(将文件里的内容全部复制过来即可)
链接验证
xxx@xxx ~ % ssh -T git@github.com Enter passphrase for key '/Users/xxx/.ssh/id_rsa': //这里输入第三步里通过终端命令创建ssh key时设置的那个密码 Hi mianchaotaiyang! You've successfully authenticated, but GitHub does not provide shell access. //表示验证成功
接下来就可以使用git命令来管理你的github项目了