Git簡單的使用步驟

Git簡單的使用步驟

本文不闡述任何概念性知識,僅僅只是做一個筆記,簡單的使用步驟,如遇障礙,請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 即可。

  2. 驗證綁定是否成功

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
Powered by ❤️ with Hugo and Stack Theme.