banner
阿珏酱

阿珏酱

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

Git簡單的使用步驟

提示:當你看到這個提示的時候,說明當前的文章是由原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 
載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。