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目录)和指定口令,保持默认,连续三次回车即可
-
复制SSH Key到GITHUB
打开该文件,id_rsa.pub文件内的内容,粘帖到github帐号管理的添加SSH key界面中
cat ~/.ssh/id_rsa.pub
登录github
-> Settings
-> SSH and GPG Keys
-> New SSH key
添加
- 测试是否连接成功
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
终于,成功!
我希望有个如你一般的人,
如山间清爽的风,
如古城温暖的光,
只要最后是你就好。
今天, 你路过了谁?
谁又丢失了你呢?
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?