🍴
Git リポジトリを GitHub に Fork する
まえがき
詳しくは参考記事を参照のこと。
とあるGitリポジトリを別のGitリポジトリにForkしたい場合の手順のまとめです。
今回の私の場合は個人がホストするGiteaからGitHubへのForkです。
- Forkもと(upstream)のコピーを維持するブランチ
- upstream/master
- Fork後(origin)の改変を維持するブランチ
- origin/main
参考
手順
- 空のGitHubリポジトリを作成(ここにForkを作る)
- GitHubリポジトリをローカルにクローン
ghq
を使っているので下記で実施
ghq get https://github.com/{user}/{repository}
移動して確認する
git remote -v
origin https://github.com/{user}/{repository} (fetch)
origin https://github.com/{user}/{repository} (push)
- upstreamを設定(=forkもと。ここからコピーする)
git remote add upstream https://git.example.com/{user}/{repogitory}.git
git remote -v
origin https://github.com/{user}/{repository} (fetch)
origin https://github.com/{user}/{repository} (push)
upstream https://git.example.com/{user}/{repogitory}.git (fetch)
upstream https://git.example.com/{user}/{repogitory}.git (push)
- upstreamをローカルリポジトリに取得
git fetch upstream
masterブランチに切り替える
git switch master
upstreamにmasterブランチがない場合はエラーになるのかも
その場合は下記の感じ?(未検証)
git switch -c master
git merge upstream/master
- mainブランチを作成し、デフォルトブランチにする
git switch -c main
git push origin main
最初に作られたブランチのため、デフォルトになる
- upstreamもpushする
git switch master
git push origin master
2番目以降に作られたブランチのため、デフォルトにはならない
- 開発していく
mainまたは開発用のブランチで作業する
git switch main
Discussion