GIT 安装与实践

论坛 期权论坛 脚本     
匿名技术用户   2021-1-15 06:51   84   0

新建库

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 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP