配置Git for Mac

一,下载git(https://git-scm.com)

选择对应系统的下载地址,进行下载

下载的软件,双击再下一步无脑安装即可。

在终端中用命令:git --verison来检查是否安装成功

二,配置git

Step 1)配置昵称和邮箱地址

 
  1. git config --global user.name "xchen"

  2. git config --global user.email "[email protected]"

  3. git config --global push.default simple


用git config -l命令可以查看配置

每次Git提交都会用到昵称和邮箱地址信息。它被嵌入了你的提交中。

Step 2)生成SSH密钥

Git是分布式的代码管理工具,远程的代码管理是基于SSH的,所以要使用远程的Git则需要SSH的配置

命令:

ssh-keygen -t rsa -C "[email protected]"

“ ”号中是我们在config中设置的邮箱地址

一路回车(默认文件路径,密钥空),会在默认路径下生成两个文件id_rsa和id_rsa.pub

其中,id_rsa.pub中存储的是SSH密钥中的公钥,我们将把它告知github

Step 3)在github中添加SSH

在Github官网https://github.com/,登录你的github帐号

settings->SSH and GPG keys

New SHH

将id_rsa.pub中存储的公钥复制过来

点击Add SSH key。

用命令:

ssh [email protected]

来测试ssh是否能够正常工作。

成功的返回应该是:

Hi xchen92hg! You've successfully authenticated, but GitHub does not provide shell access.

三,使用github

Step 1)进入你知道项目文件夹下

 
  1. git init

  2. git add README.md

  3. git commit -m "first commit"


Step 2)提交

 
  1. git remote add origin [email protected]:你的github账户名/项目名.git

  2. git push -u origin master


 

此时,我们再登录github就会发现,项目已经同步到github中了。

PS:

1)github 遇到Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts问题解决

警告:为IP地址192.30.252.128的主机(RSA连接的)持久添加到hosts文件中,那就来添加吧!

解决办法:

   vim /etc/hosts

添加一行:192.30.252.128  github.com

2)用vi编辑文件为readonly应该怎么设置

解决办法:

sudo vim 文件

输入密码,修改完用:wq!就可以保存了

3)ssh:connect to host github.com.port 22:Connection refused

解决办法:

vim .ssh/config

编辑为

Host github.com

User [email protected]

Hostname ssh.github.com

PreferredAuthentications publickey

IdentityFile ~/.ssh/id_rsa

Port 443

再用ssh [email protected]来测试

显示

You've successfully authenticated, but GitHub does not provide shell access

就成功了。

猜你喜欢

转载自blog.csdn.net/cqg1988/article/details/81272692