Linux(Centos 7)下安装Git并配置连接GitHub

1、安装git  Centos7 查看git --version 

2、配置用户名密码

git config --global user.name "xxx"
git config --global user.email "xxx@gmail.com"

3、为GitHub账号添加SSH Keys
ssh-keygen -t rsa -C "qiubing.it@gmail.com" 生成key
系统会提示key的保存位置(一般是~/.ssh目录)和指定口令,保持默认,连续三次回车即可

  1. 复制SSH Key到GITHUB

打开该文件,id_rsa.pub文件内的内容,粘帖到github帐号管理的添加SSH key界面中

cat ~/.ssh/id_rsa.pub

登录github-> Settings-> SSH and GPG Keys-> New SSH key添加

  1. 测试是否连接成功
ssh -T git@github.com

会提示

The authenticity of host 'github.com (192.30.255.112)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes

直接输入 yes 就可以了,然后提示成功:

Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.
Hi smartwen! You've successfully authenticated, but GitHub does not provide shell access.

git推送到GitHub步骤:

git init

git add file

git commit -m "注释"

git remote add origin git@github.com:smartwen/selIDE

git push -u origin master

 解决一个巨坑

我使用了命令:

git push -u origin master
结果报错如下:
error: failed to push some refs to 'git@github.com:你的远程库名.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
从提示可以看出,是由于两者不同步,因此需要先pull,进行合并然后在进行push,
因此先使用
git pull --rebase origin master
将远程文件同步下来。
然后再执行推送
git push -u origin master
终于,成功!
 

 

 

 

 

 

 


posted @   smartwen  阅读(4655)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示