Git简单的使用步骤
Tips:当你看到这个提示的时候,说明当前的文章是由原emlog博客系统搬迁至此的,文章发布时间已过于久远,编排和内容不一定完整,还请谅解`
Git简单的使用步骤
日期:2018-4-3 阿珏 教程 浏览:2117次 评论:0条
本文并不阐述任何概念性知识,仅仅只是做一个笔记,简单是使用步骤,如遇障碍,请Google一下
使用SSH 完成 Git 与 GitHub 的绑定
- 生成
SSH key
ssh-keygen -t rsa
指定 RSA 算法生成密钥,之后就就会生成两个文件,分别为id_rsa和id_rsa.pub,即密钥id_rsa和公钥id_rsa.pub. 对于这两个文件
-
添加
SSH key
github.com ->
Settings ->
SSH and GPG -> New SSH key
将公钥id_rsa.pub的内容粘贴到Key处的位置(Titles的内容不填写也没事),然后点击Add SSH key 即可。 -
验证绑定是否成功
ssh -T git@github.com
把本地项目推送到github的命令
(1) 打开你的目录
cd demo
(2) 初始化版本库,用于生成git文件
git init
(3) 将所有文件添加到缓存区
git add *
(4) 提交当前工作空间的修改内容
git commit -m "first commit"
(5) 将仓库连接到远程服务器
git remote add origin <server>(就是上面你仓库的地址)
(6) 将改动推送到所添加的服务器上
git push -u origin master
在推送的时候如果出现如下错误:
warning: redirecting to https://github.com/178146582/dabai.git/
To http://github.com/178146582/dabai.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'http://github.com/178146582/dabai.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
查了一下错误的原因是github中的README.md文件不在本地代码目录中。所以我们把上面第六步分成两步:
git pull --rebase origin master:进行代码合并
git push -u origin master
本博客所有文章 如无特别注明 均为原创。 作者: 阿珏酱 , 复制或转载请 以超链接形式 注明转自 阿珏酱博客 。 原文地址:https://www.cnblogs.com/Ajue/p/18202103