打开终端,运行cd ~/.ssh
如果路径下无文件,直接跳过下一步,如果有代表有ssh key,需进行第二步进行备份
b、备份已有的key,(如果有的话)
mkdir key_backup
mv id_rsa* key_backup
c、.生成SSH key
$ ssh-keygen -t rsa -C jonezhang86@gmail.com(注册的main邮箱)
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/jiangbo/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in yes.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
fb:c4:b0:e0:47:fd:be:e0:fb:ea:73:ef:a8:29:d5:22 jonezhang86@gmail.com
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |
| . |
| . S .. |
| . oE=o.. |
| . +o+.. |
| ..+.+.. |
| oOB=+o |
+-----------------+
4)将SSH key添加到coding上
a、打开终端,输入open ~/.ssh,查看id_rsa.pub这个文件并打开拷贝key值
b、打开coding官网,登录成功后,点击账户-SSH公钥,输入a步拷贝的值,点击提交
5)建立本地仓库并初始化
1、命令行打开本次仓库的文件夹目录或者直接创建
cd !/(目录)
2、仓库初始化
git init
3、将项目克隆到本地仓库
git clone URL(项目的SSH地址)
4、更新远程更新到本地:
先打开本地仓库的目录,要是程序文件夹的目录
然后输入更新代码命令,如下所示:
git pull
5、提交代码
常见问题记录FAQ
1.git pull代码的时候报如下错:
error: Your local changes to the following files would be overwritten by merge:
Please, commit your changes or stash them before you can merge.
这表示更新下来的内容和本地修改的内容有冲突,先提交你的改变或者先将本地修改暂时存储起来
解决方法:先将本地内容存储起来,运行命令:git stach
再git pull 即可
2、git pull的时候报如下错:
fatal: No remote repository specified. Please, specify either a URL or a
remote name from which new revisions should be fetched.
问题:打开的路径不对
解决方法:打开本次仓库的正确路径,在更新代码
参考博文如下: