背景
以 Windows 電腦及 Windows PowerShell 為例,將流程分為兩個情境:
- Part 1 — Remote 端尚未建立 Repository
- Part 2 — Remote 端已建立 Repository
Part 1 — Remote 尚未建立 Repo
1
安裝 GitHub CLI
winget install --id GitHub.cli
gh --version2
授權登入
gh auth login3
切換至 Local 資料夾
cd /your/project/path4
初始化 Git 紀錄
git init
git add .
git commit -m "Initial commit"
git branch -M main5
建立 Repo 並上傳
gh repo create project-name --public --source=. --remote=origin --push可替換
--public 為 --privatePart 2 — Remote 已建立 Repo
1
切換至 Local 資料夾
cd /your/project/path2
初始化 Git 儲存庫
git init3
加入暫存區並提交
git add .
git commit -m "Initial commit"4
設定主要分支名稱
git branch -M main5
連結 GitHub Repository
git remote add origin <repo-url>6
Remote 有既有檔案時
git pull origin main --allow-unrelated-histories若 Remote 無任何檔案可跳過。
執行後進入 Vim:按
執行後進入 Vim:按
Esc → 輸入 :wq → Enter7
Push 到 Remote
git push -u origin main