Github - Note

Github - Note

LAVI

Instruction

  1. 新建本地數據庫

    1
    git init
  2. 將檔案加入索引中

    1
    git add .
  3. 查看檔案
    我都用來回憶一下剛剛推了什麼,方便寫 commit

    1
    git status
  4. 將索引中的檔案提交到本地數據庫
    commit 可以寫一些更新的內容,方便知道本次更新了什麼,像是註解,方便維護

    1
    git commit -m "upload"
  5. 新增分支

    1
    git branch -M main
  6. 新增遠端連線

    1
    git remote add origin <ssh git@github.com:lavinia0724/test.git>
  7. 查看遠端連線

    1
    git remote -v
  8. 把本地數據庫檔案推上 github

    1
    git push -u origin main
  9. 把 github 上的檔案拉到本地數據庫

    1
    git pull

引用外部檔案

如果推上 github 的檔案中有 clone 別人的檔案,在推上 github 後會顯上白色箭頭且無法打開
原因是在本機的資料夾中有 .git 隱藏資料夾

解決辦法:

  1. 刪除資料夾中的 .git 隱藏資料夾

在有 .git 的資料夾路徑下,點擊上方的 三個點,然後選擇 檢視, 點選 顯示隱藏的檔案、資料夾及磁碟機
按確定後就會出現隱藏的資料夾了

  1. 在此資料夾的父資料夾路徑下,執行以下指令
    1
    git rm --cached <資料夾名稱>

刪除完 cache 後,就可以普通的回到推本機資料上 github 的指令環節了

儲存大型檔案

使用 git LFS
先在本機安裝 git LFS

用指令安裝好 git lfs

1
git lfs install

將指定大型檔案加入 git lfs 追蹤

1
git lfs track <檔案名稱或資料夾>

新增一個 .gitattributes 檔案
內容為該檔案名稱(或資料夾)

接著就普通的

1
2
3
git add .
git commit -m "add large file"
git push origin main

clone 的時候可以用

1
git lfs clone

pull 的時候可以用

1
git lfs pull

Error Fix

error: The following untracked working tree files would be overwritten by merge:

解決方式:

1
git fetch origin
1
git clean -f
1
git reset --hard origin/main

Your branch is ahead of ‘origin/main’ by 2 commits. (use “git push” to publish your local commits)

解決方式:

1
git reset --hard origin/main

但是會把整個整個專案回復到最後一次 git 更新的紀錄,reset 前檔案資源要記得自己先備份!!

Reference