完全に個人的な備忘録

完全に個人的な備忘録。学習コストが高くなってきたので、メモしておかないと…片っ端から忘却の彼方なのです。

gitリポジトリの引越

久々に osdn にアクセスしたところ、レスポンスが帰って来ない…正確には全くアクセスできないわけではないのだが、かなり重い。殆ど使えない状態になってた。

504 Gateway Time-out

が大量発生する。調べてみたところ、最近、売却されて、それ以降、接続しにくい状態が続いているようだ。こんな状態では、何時、アクセスできなくなるかもしれないので、引越を行なう事にした。Wiki等の引越は諦めるとして、リポジトリだけは引っ越したい。
幸いにして、gitからリポジトリのアクセスはできるようなので、早めに引っ越す事にした。引越先は github にしました。

以下、手順です(リポジトリは架空です)。

移行元のリポジトリを --mirror オプションで clone します。

$ git clone --mirror https://pf.osdn.net/gitroot/t/ta/taratara/hogehoge.git
Cloning into bare repository 'hogehoge.git'...
remote: Counting objects: 285, done.
remote: Compressing objects: 100% (166/166), done.
remote: Total 285 (delta 119), reused 268 (delta 111)
Receiving objects: 100% (285/285), 73.18 KiB | 663.00 KiB/s, done.
Resolving deltas: 100% (119/119), done. 

cloneしたディレクトリに移動します。

$ cd hogehoge.git/

移行先のリポジトリへ --mirror オプションでプッシュします。

 git push --mirror https://github.com/taratara/hogehoge.git
Enumerating objects: 285, done.
Counting objects: 100% (285/285), done.
Compressing objects: 100% (158/158), done.
Writing objects: 100% (285/285), 73.18 KiB | 18.30 MiB/s, done.
Total 285 (delta 119), reused 285 (delta 119), pack-reused 0
remote: Resolving deltas: 100% (119/119), done.
To https://github.com/taratara/hogehoge.git
 * [new branch]      master -> master
 * [new tag]         convert-from-cvs -> convert-from-cvs
 * [new tag]         r-hogehoge -> r-hogehoge
 ! [remote rejected] main (refusing to delete the current branch: refs/heads/main)
error: failed to push some refs to 'https://github.com/taratara/hogehoge.git'

ところがエラー発生。
デフォルトのブランチ名が一致していないのが原因です。github のデフォルトのブランチ名が master から main に変更になっているが原因です。

移行先のデフォルトブランチ名を main から master に変更してから再度実行したところ問題なく移行できました。

$ git push --mirror https://github.com/taratara/hogehoge.git
Enumerating objects: 248, done.
Counting objects: 100% (248/248), done.
Compressing objects: 100% (110/110), done.
Writing objects: 100% (212/212), 39.57 KiB | 4.95 MiB/s, done.
Total 212 (delta 114), reused 198 (delta 100), pack-reused 0
remote: Resolving deltas: 100% (114/114), completed with 19 local objects.
To https://github.com/taratara/hogehoge.git
 + 8eab0a8...8392bbb master -> master (forced update)

勿論、ブランチ名を指定して push する方法もあるんですけどね。

    • -

上記は github側で git init でリポジトリの初期化を行なってしまった為にデフォルトのブランチが作成されてしまい、ブランチ名が一致しない事により、エラーになってしまったが、github側でリポジトリの初期化を行なわなければ問題なく移行できる。

git init を行なっていない状態

この状態であれば、そのままエラーが発生する事なく引越が完了します。

git push --mirror  https://github.com/tarancho/jbanner.git
Enumerating objects: 50, done.
Counting objects: 100% (50/50), done.
Delta compression using up to 2 threads
Compressing objects: 100% (46/46), done.
Writing objects: 100% (50/50), 43.08 KiB | 689.00 KiB/s, done.
Total 50 (delta 17), reused 0 (delta 0)
remote: Resolving deltas: 100% (17/17), done.
To https://github.com/tarancho/jbanner.git
 * [new branch]      master -> master
 * [new tag]         Version-1.0 -> Version-1.0
 * [new tag]         convert-from-cvs -> convert-from-cvs
 * [new tag]         release -> release

次に既存の編集中の clone したリポジトリが存在している場合は、リモートURLを更新します。

現在のURLを確認します。

git remote -v
origin  tarancho@git.pf.sourceforge.jp:/gitroot/t/ta/tarancho/jbanner.git (fetch)
origin  tarancho@git.pf.sourceforge.jp:/gitroot/t/ta/tarancho/jbanner.git (push)

URLを移行先に変更します。

git remote set-url origin https://github.com/tarancho/jbanner.git

URLを確認します。

git remote -v
origin  https://github.com/tarancho/jbanner.git (fetch)
origin  https://github.com/tarancho/jbanner.git (push)

新しいリモートリポジトリと同期します。

git pull
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 11 (delta 7), reused 4 (delta 0), pack-reused 0
Unpacking objects: 100% (11/11), done.