GitHub CLI 和 git 使用
簡單筆記自己會用到 git 或 gh 的指令或方法。
安裝、升級
macOS
Homebrew
安裝
brew install git
brew install gh
升級
brew upgrade git
brew upgrade gh
常見用法
建置
登入
gh auth login
從本地端資料夾建立 repositry
- 在命令列移至欲使用的資料夾本身 (根目錄)
- 初始化此資料夾
- 新增 (stage) 且 commit 所有既有內容;若為新的空資料夾,略過此步驟
- 建立 repository
cd {資料夾路徑}
git init
git add . && git commit -m "initial commit"
gh repo create
或:
cd {資料夾路徑}
git init
gh repo create {資料夾名稱} --private --source=. --remote=upstream
將遠端 repositry 複製到本地端
cd {根目錄路徑}
gh repo clone {username}/{repository name}
管理
顯示目前狀態、列出 branch
git status
git branch
更改 branch 名稱
git branch -m {舊名稱} {新名稱}
合併分支
git checkout {合併主體}
git merge {合併對象}
異動
命令列必須位於該 repository 的本地根目錄
推送 commits 至 repository
- 新增 (stage) 異動的檔案或資料夾
- Commit 異動
- 推送至 repository
git add {異動的資料夾或檔案}
git commit -m "異動的說明"
git push origin main
拉取遠端 repository 至本地端更新
git pull
留言
張貼留言