GIT 安装与实践

新建库

1、本地配置用户名和邮箱:
git config --global user.name "你的用户名"
git config --global user.email "你的邮箱"


2、生成ssh key
运行 ssh-keygen -t rsa -C "你的邮箱" ,它会有三次等待你输入,直接回车即可。

将生成的ssh key复制到剪贴板,执行 clip < ~/.ssh/id_rsa.pub 


3、打开Github,进入Settings:

点击左边的 SSH and GPG keys ,将ssh key粘贴到右边的Key里面。Title随便命名即可。
点击下面的 Add SSH key 就添加成功了。

测试一下吧,执行 ssh -T git@github.com :
Hi tingroger! You've successfully authenticated, but GitHub does not provide shell access.

嗯,这样就成功了!


4、创建远程仓库
首先是在右上角点击进入创建界面,接着输入远程仓库名,点击 Create repository 就创建好了。


5、将远程仓库和本地仓库关联起来

先到Github上复制远程仓库的SSH地址,有两种方式可以关联,一种是SSH,一种是HTTPS。由于HTTPS比较慢,所以推荐使用SSH。
注意SSH的地址格式是这样开头的: git@github.com

运行 git remote add origin 你复制的地址。
如果你在创建 repository 的时候,加入了 README.md 或者 LICENSE ,那么 github 会拒绝你的 push 。
你需要先执行 git pull origin master。

执行 git push -u origin master 将本地仓库上传至Github的仓库并进行关联

 

关联已经完成!

以后想在commit后同步到Github上,只要直接执行 git push 就行啦

 

初次使用

初次使用会出现以下告警:

$ git clone git@github.com:tingroger/MY-LIB.git

Cloning into 'MY-LIB'...

Warning: Permanently added the RSA host key for IP address '192.30.253.113' to the list of known hosts.

git@github.com: Permission denied (publickey).

fatal: Could not read from remote repository.

 

Please make sure you have the correct access rights

and the repository exists.

一般而言确认自己的email和name即可:

git config --global user.name "你的用户名"

git config --global user.email "你的邮箱"

 

 

 

Warning: Permanently added the RSA host key for IP address '192.30.253.113' to the list of known hosts.

解决方案:

在hosts文件中加入github.com就可以了

我的centos服务器,vi /etc/hosts

 

wq 保存

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值