GitHub note


Posted by ericcch24 on 2020-06-22

  • GitHub 是什麼 -- 遠端放 Git repository 的地方(還有很多其他功能)

  • 如何把 code 放上 github -- git remote add origin github網址 >> 然後 git push -u origin master

    • commit 完之後要 git push 才會同步上傳至 github 上的 branch
  • git pull branch-name -- 把 github 遠端的 branch 資料拉來本地
    • 在 local 本地的 git 有改動,就要 push 上去,在 github 上有改動,就要pull下來,時時確保兩邊是同步的狀態。
  • git clone 東西的網址 -- 抓別人的東西,或先 fork 到自己的 github 再 clone。


  • 也可以在 github 上進行 branch merge(pull request)合併,然後 pull 到 local 本地。

    • GitHub Flow: 有要改任何東西時 >> 先開 branch 然後開始改 >> 改完後 open pull request(要求 merge 的概念) >> 討論改動 >> merge
  • GitHub Pages 免費的網頁空間:在 setting 裡設定,可以拿來放作品集。


Git 狀況劇

  • commit message 打錯字:用 git commit --amend 修正
  • 已經 commit 了可是後來反悔了:用 git reset HEAD^ --三種模式

    • git reset HEAD^ --soft 較常用,因為通常只是要回去改一些小東西,不用 --hard 把整個 commit reset,如果 HEAD^ 後面空白的預設是 --mixed
    • 參考連結
  • 還沒 commit,但改的東西不想要了git checkout (or restore) -- <file> 可以把改過但還沒 commit 的檔案回朔到上個狀態。註:後面加.的話就是把所有改過的檔案回朔(與 git add ..意思相同)

  • 改 branch 名稱git branch -m new name

  • 把遠端 branch 抓下來git checkout branch-name

  • Hook -- 發生某事的時候通知我
    • 例如在 hooks 資料夾中的 pre-commit檔案設定一些條件的程式碼讓我在這個條件發生時不能 commit 等等,在 commit 之前作檢查的概念。

#Week 1







Related Posts

【Day05】Youtube GUI 下載程式

【Day05】Youtube GUI 下載程式

如何使用 Python 程式操作 Excel 試算表

如何使用 Python 程式操作 Excel 試算表

How to compare a fixed date stored in an object with the current date in JavaScript?

How to compare a fixed date stored in an object with the current date in JavaScript?


Comments