1.安装。
首先查看电脑是否安装Git,终端输入: git --version 1)通过homebrew安装Git 未安装homebrew,需安装homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 2)安装git brew install git
2.快捷键。
git --version 查看版本。
git config --list 查看配置信息。
git config --global user.name yourname 全局配置git用户名。
git config --global user.email youremail 全局配置git邮箱。
3.创建ssh key。
查看是否已经存在:cd ~/.ssh
如果没有,则可以直接安装,如果存在,需要备份删除或者直接删除:mkdir key_backup cp id_rsa* key_backup rm id_rsa*
4.设置username和email。(每次commit都会记录)
git config --global user.name "xxx"
git config --global user.email "xxx@xx.com"
5.通过命令终端创建ssh key。
ssh-keygen -t rsa -C "xx@xx.com"
一路回撤即可。
【图片】
成功的话生成~/.ssh文件夹。查看公钥,复制里面的key。或者使用cat命令查看:cat .ssh/id_rsa.pub
open .ssh/id_rsa.pub
No application knows how to open /Users/janeyork/.ssh/id_rsa.pub.
6.复制ssh key到GitHub。
头像 - setting - ssh key - new ssh key
7.测试链接。
ssh -T git@github.com
JaneYorkdeMBP:~ janeyork$ ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '13.229.188.59' to the list of known hosts.
Hi JaneYork! You've successfully authenticated, but GitHub does not provide shell access.
8.新建一个仓库。
填写相关信息:
9.clone工程到本地。(首先复制ssh地址)
例如,clone到桌面,先切换目录到桌面。
cd /Users/janeyork/Desktop/
git clone git@github.com:JaneYork/temp.git
10.提交修改。(不支持空文件夹提交)
//文件添加到仓库(.代表提交所有文件) git add . //把文件提交到仓库 git commit -m "" //上传到github git push
JaneYorkdeMBP:temp janeyork$ git status
On branch master
Your branch is up to date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
hehe/
nothing added to commit but untracked files present (use "git add" to track)
JaneYorkdeMBP:temp janeyork$ git add .
JaneYorkdeMBP:temp janeyork$ git commit -m "xxx"
[master 4d9abad] xxx
1 file changed, 2 insertions(+)
create mode 100644 "hehe/README\347\232\204\345\211\257\346\234\254.md"
JaneYorkdeMBP:temp janeyork$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 314 bytes | 314.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:JaneYork/temp.git
23ade32..4d9abad master -> master
JaneYorkdeMBP:temp janeyork$