Skip to content

[GitHub] 如何將 public repo 調整成 private repo

Published: at 02:43 AM (1 min read)

前陣子在改非常舊的沒有 LICENSE 的故障 public repo 時,想說要先改成 private repo 後,要發佈時再調整為 public repo,才發現在 Github 沒辦法直接一鍵調整成 private repo

GitHub create private fork from public repo

這時候需要改成使用 Duplicating a repo 的步驟進行,例如:

我要 duplicate 一個 public repo camel2243/camel-blog-commentsprivate repo

  1. 建立一個 Bare clone repo (僅有 git 歷史紀錄)
git clone --bare [email protected]:camel2243/camel-blog-comments.git
  1. Github 上建立一個新的 private repo <your_username>/new-repo

  2. 將 Bare clone repo 推到新的 repo

cd camel-blog-comments.git
git push --mirror [email protected]:<your_username>/new-repo.git
  1. 刪除 Bare clone repo
cd ..
rm -rf camel-blog-comments.git
  1. Clone 你的新 repo
git clone [email protected]:<your_username>/new-repo.git
  1. 這時你可以在 設定 中看到你的 repo 是 private repo,並且可以進行相關設定 🎉

GitHub create private fork from public repo

參考資料


Next Post
[leetcode] 14. Longest Common Prefix