git Remote 常見情境與操作

📌 Git Remote 常見情境與操作

情境 指令範例 說明
新增 remote git remote add origin https://github.com/user/repo.git 在新建的 repo 裡,第一次綁定遠端倉庫。origin 是慣例名稱。
查看 remote git remote -v 檢查目前 repo 綁定的遠端 URL(fetch/push)。
修改 remote URL git remote set-url origin https://github.com/user/new-repo.git 當遠端倉庫搬家或改用 SSH/HTTPS 時,更新 URL。
移除 remote git remote remove origin 不再需要某個遠端時,刪除它。
多個 remote git remote add upstream https://github.com/other/repo.git Fork 專案時,除了 origin,還會加上 upstream 來追蹤原始倉庫。
檢查 remote 詳細資訊 git remote show origin 顯示遠端的詳細設定(branch 對應、push/pull 狀態)。

💡 常見錯誤與排查

  • URL 設錯 → 用 git remote set-url 修正。
  • 忘記加 remote → push 時會出現錯誤:fatal: No configured push destination,需要先 git remote add
  • 多個 remote 搞混 → 建議用清楚的名稱,例如 origin(自己的 repo)、upstream(原始專案)。
  • SSH/HTTPS 認證問題 → 如果 HTTPS 要輸入帳號密碼,可以改用 SSH key。

Also See

File14FileLast Modified
把目前repo 所有的branch都push 到github把目前repo 所有的branch都push 到github2:24 PM - January 12, 2026
把目前 branch 上的修改(尚未 commit 的檔案)直接帶到一個新的 branch把目前 branch 上的修改(尚未 commit 的檔案)直接帶到一個新的 branch2:24 PM - January 12, 2026
從 Windows 把 repo 搬到 WSL再一次性 push 所有 branch 到GitHub 這樣就能避開 aux 檔名問題從 Windows 把 repo 搬到 WSL再一次性 push 所有 branch 到GitHub 這樣就能避開 aux 檔名問題2:24 PM - January 12, 2026
git指定初始化的 branch 名稱git指定初始化的 branch 名稱2:24 PM - January 12, 2026
github上的repo clone下來check out 某一個dev branchgithub上的repo clone下來check out 某一個dev branch2:24 PM - January 12, 2026
github一台電腦同時使用兩個 GitHub 帳號github一台電腦同時使用兩個 GitHub 帳號2:24 PM - January 12, 2026
github actionsgithub actions2:24 PM - January 12, 2026
git 重新再從github上pull 所有branchgit 重新再從github上pull 所有branch2:24 PM - January 12, 2026
Git 裡查看 configurationGit 裡查看 configuration2:24 PM - January 12, 2026
git 恢復到最近一次 git pull狀態,取消本地修改git 恢復到最近一次 git pull狀態,取消本地修改2:24 PM - January 12, 2026
git 初始化與推送流程圖git 初始化與推送流程圖2:24 PM - January 12, 2026
git 中查看commit歷史資訊git 中查看commit歷史資訊2:24 PM - January 12, 2026
git 中修改檔名且保留原來commit紀錄git 中修改檔名且保留原來commit紀錄2:24 PM - January 12, 2026
git GUI tool, SourceTreegit GUI tool, SourceTree2:24 PM - January 12, 2026