终端
cd ~/.ssh
#协议为rsa 大小为4096
ssh-keygen -t rsa -b 4096
[密钥名称] #密钥名称 可缺省
[密钥密码] #密码密码 可却省(感觉没有必要)假设为的密钥名称是rads_mac
现在应该出现了rads_mac和rads_mac.pub两个文件,分别是私钥和公钥
复制公钥文件添加到github中
还需要在密钥同目录下创建config文件,内容如下
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/rads_mac最后一行的rads_mac是我的密钥名称
再到某空目录下执行git clone [SSH]就可以拉取仓库了
对于任何在本地创建的文件,需要先git add [filename],这样在提交时该文件才会被包括在被提交文件中
如果想add某个文件夹应该 git add [foldername/],需要在后面加上斜线
对于git clone得到的文件则不需要使用git add
修改文件时,修改的是本地文件而非本地仓库的文件
需要使用git commit -a -m "[commit message]"来提交到本地仓库
-a意为所有文件,-m是提交的备注信息
然后使用git push就可以推送到远程仓库了
git pull
git config --global user.name "my name" #设置name
git config --global user.email "my email" #设置email
git config --global --list #查看git配置信息只有config文件内容不同
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile C:/Users/[username]/.ssh/rads_win报错:
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
修改~/.ssh/config如下即可
# github
Host github.com
HostName ssh.github.com
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/rads_mac