Git 常用指令 === ###### tags: `git` ### 本機端相關 >建置Git儲存庫 ```linux git init ``` >單一檔案加入索引 ```linux git add {檔案路徑} ``` >所有檔案加入索引 ```linux git add . ``` >commit(提交目前版本) ```linux git commit -m {填寫此版本訊息} ``` >切換至某個commit ```linux git checkout {commitId} ``` >觀看當前狀態(索引) ```linux git status ``` >瀏覽歷史紀錄(commit) ```linux git log ``` >瀏覽圖形化內容 ```linux gitk ``` ### Branch相關 >切換到已存在的branch(分支) ```linux git checkout {branch名} ``` ```linux git switch {branch名} ``` >新增並切換branch ```linux git checkout -b {branch名} ``` ```linux git switch -c {branch名} ``` ### 遠端相關 >設定遠端Git儲藏庫資訊 ```linux git remote set {遠端名} {ssh位址or網址} ``` >從遠端Git儲存庫下載專案(初次) ```linux git clone {ssh位址or網址} ``` >同步程式碼(遠端->本機端) ```linux git fetch ``` >同步程式碼並自動合併 ```linux git pull ``` >將遠端branch拉回本機端 ```linux git checkout -b {新branch的名稱}{遠端名}/{遠端branch名} ``` >更新目前分支 ```linux git push {遠端名}{本機端branch名} ``` :::info **P.S.** - 如果有執行過git push --set-upstream {遠端名} {本地branch名}的話,僅需要下git push即可。 - 如果要將本機端的分支更新至遠端也是一樣的指令。 :::