1,安装git
查看mac上是否已安装git
git --version
如果没有,可以通过安装Xcode后配置,或者通过 xcode-select --install 安装。具体安装方法请百度。
2,创建github账号
创建github的邮箱后面会用到
3,创建ssh,配置本地git
参考:Git - 初次运行 Git 前的配置 (git-scm.com)
https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%88%9D%E6%AC%A1%E8%BF%90%E8%A1%8C-Git-%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE
设置username和email(github每次commit都会记录他们)
git config --global user.name "xxx"
git config --global user.email
[email protected] //注册github的邮箱
如果要查看配置,使用如下命令
git config --list
通过终端命令创建ssh key
xxx@xxx ~ % ssh-keygen -t rsa -C
[email protected] //注册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_rsaYour public key has been saved in /Users/xxx/.ssh/id_rsa.pubThe key fingerprint is:SHA256:xxx/xxxxxxx
[email protected] 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:
打开https://github.com并登录,进入到 “Account Setting”,在左侧导航栏找到“SSH and GPG keys”,点击,然后右侧内容里 “SSH keys” 右侧按钮 “New SSH key”
打开的页面里输入 Title 和 Key
Title 可以随便填,Key 是第三步.ssh/id_rsa.pub文件里的密钥(将文件里的内容全部复制过来即可)
链接验证
xxx@xxx ~ % ssh -T
[email protected]
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项目了