banner
阿珏酱

阿珏酱

乘上与平常相反的电车,去看看那未曾见过的风景
twitter
github
facebook
bilibili
zhihu
steam_profiles
youtube

Git简单的使用步骤

Tips:当你看到这个提示的时候,说明当前的文章是由原emlog博客系统搬迁至此的,文章发布时间已过于久远,编排和内容不一定完整,还请谅解`

Git 简单的使用步骤

日期:2018-4-3 阿珏 教程 浏览:2117 次 评论:0 条

本文并不阐述任何概念性知识,仅仅只是做一个笔记,简单是使用步骤,如遇障碍,请 Google 一下

使用 SSH 完成 Git 与 GitHub 的绑定#

  1. 生成

SSH key

ssh-keygen -t rsa

指定 RSA 算法生成密钥,之后就就会生成两个文件,分别为 id_rsa 和 id_rsa.pub,即密钥 id_rsa 和公钥 id_rsa.pub. 对于这两个文件

  1. 添加 SSH key
github.com -> Settings -> SSH and GPG -> New SSH key 将公钥id_rsa.pub的内容粘贴到Key处的位置(Titles的内容不填写也没事),然后点击Add SSH key 即可。
  1. 验证绑定是否成功

把本地项目推送到 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 
加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。