创建ssh
a、检查SSH key
打开终端,运行cd ~/.ssh
如果路径下无文件,直接跳过下一步,如果有代表有ssh key,需进行第二步进行备份
b、备份已有的key,(如果有的话)
mkdir yjf_biv
mv id_rsa* yjf_biv
c、.生成SSH key
$ ssh-keygen -t rsa -C menyk.1@jifenn.com(注册的main邮箱)
`Generating public/private rsa key pair.
Enter file in which to save the key (/Users/menyongkang/.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 menyk.1@jifenn.com
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |
| . |
| . S .. |
| . oE=o.. |
| . +o+.. |
| ..+.+.. |
| oOB=+o |
+-----------------+
`
将SSH key添加到coding上
a、打开终端,输入open ~/.ssh,查看id_rsa.pub这个文件并打开拷贝key值
b、打开gitLab官网,登录成功后,点击账户-SSH公钥,输入a步拷贝的值,点击提交
建立本地仓库并初始化
1、命令行打开本次仓库的文件夹目录或者直接创建
cd !/(目录)
2、仓库初始化
git init
3、将项目克隆到本地仓库
git clone URL(项目的SSH地址)
常见问题记录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.
问题:打开的路径不对
解决方法:打开本次仓库的正确路径,在更新代码
- git clone 是报错 ` menyongkangdeMacBook-Pro:code menyongkang$ git init
Initialized empty Git repository in /Users/menyongkang/Desktop/YJF/code/.git/
menyongkangdeMacBook-Pro:code menyongkang$ git clone git@git.dev.enbrands.com:biv/biv_ecrm_skystrat.git
Cloning into 'biv_ecrm_skystrat'...
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for '/Users/menyongkang/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/Users/menyongkang/.ssh/id_rsa": bad permissions
git@git.dev.enbrands.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.
解法方法:chmod -R 700 ~/.ssh`