首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計綜合問答

GitHub Desktop 創建 Repository 失敗:本地創建後需推送至遠程

     編輯:程式設計綜合問答

問題現象

GitHub Desktop 客戶端點擊創建 Repository 失敗,提示錯誤信息。

根因與標準流程

GitHub Desktop **主要用於管理本地倉庫並同步至 GitHub 遠程**,**不能直接在遠程創建倉庫**(舊版可能支持,新版已移除/需登錄授權)。標準流程:

正確操作步驟

  1. 在 GitHub 網頁端創建倉庫:
    • 登錄 github.com → 右上角 `+` → `New repository`。
    • 填寫名稱、描述、選擇 Public/Private、**勾選 `Add a README file`** (推薦)。
    • 點擊 `Create repository`。
  2. 在 GitHub Desktop 克隆/添加:
    • File → `Clone repository` → 選擇剛創建的倉庫 → 選擇本地路徑 → `Clone`。
    • 或:本地已有項目 → File → `Add local repository` → 選擇項目根目錄 → `Repository` → `Repository settings` → `Remote` 添加 `origin` URL → `Publish repository` 推送至 GitHub。

常見錯誤原因

現象原因解決
Desktop 創建失敗未登錄/Token 過期/無權限/網絡不通File → Options → Accounts 重新登錄/更新 Token
Publish 失敗遠程已有同名倉庫/未關聯 Remote網頁端創建同名倉庫 → Desktop Clone / 手動添加 Remote URL
Push 被拒遠程有本地無的提交 (README/LICENSE)先 `Fetch origin` → `Pull` (rebase/merge) → 再 `Push`

命令行等價操作 (理解本質)


# 1. 本地初始化
git init
git add .
git commit -m "Initial commit"

# 2. 關聯遠程 (需先在網頁創建)
git remote add origin https://github.com/username/repo.git

# 3. 推送
git push -u origin master/main

總結

**GitHub Desktop 不直接在遠程創建倉庫**。**先在 github.com 網頁創建**,再用 Desktop **Clone** 或 **Add Local + Publish**。這符合 Git 分布式本質:遠程倉庫獨立存在,本地通過 Remote 關聯同步。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved