Subversion から Git へ移行したリポジトリを Gitサーバーへ移入する [wsl]

前回の Subversion から Git へ移行 [wsl] にて、SVN リポジトリから変換して出来た Git リポジトリがローカルにあるので、今回は Git リポジトリを Git サーバーへ上げていきます。

サーバーに空のリポジトリを作る

Git サーバーに空のリポジトリを作成します。
Git が使えるサービスならどこでも大きな違いは無いと思いますが、私が利用している Bitbucket で作っていきます。

Create のドロップダウンを表示して、リポジトリを選択します。

作成するリポジトリの情報を入力して、[リポジトリの作成]をクリックします。
例では、README を含めず、.gitignore を含めるようにしています。

作成されました。

サーバーへ push する

ここからは WSL 上での作業です。

credential.helper を設定に追加する

WSL 上で Bitbucket から git clone したり、Bitbucket へ push したりするには、credential.helper を追加する必要があります。追加しないと Authentication failed になって実行できません。

credential.helper の値に Git for Windows をインストールしたときに入った git-credential-manager-core.exe を指定しますので、git-credential-manager-core.exe が入っている場所を探します。

上のコマンドで発見した git-credential-manager-core.exe のパスを git config に追加します。

設定状況を確認しておきます。

master を git push する

サーバーの URL を設定に追加

fetch や push が出来るように、サーバー(Bitbucket) の URL を .git/config に追加します。ここでは、ファイルを直接編集するのではなく、コマンドで追加しています。

設定されたことを確認します。

git fetch

リモート追跡ブランチの origin/master を取得します。

ここから git fetch → git merge → git push の順に実行していきますが、この順ではなく、git push URL指定をすると Updates were rejected because the remote contains work that you do not have locally. となります。

Bitbucket でリポジトリを作るときに 「Include .gitignore?」を Yes にしたため、リモート側に .gitignore があって、ローカルに無いという差が出ているためです。

$ git push https://username@bitbucket.org/username/madokae.git
To https://bitbucket.org/username/madokae.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://username@bitbucket.org/username/madokae.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull …') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

確認します。git branch -a で見ると、最後に remotes/origin/master が追加されています。

git merge

fetch した remotes/origin/master とローカルの master に入っている内容をマージします。

--allow-unrealted-histories

祖先が違うので –allow-unrelated-histories オプションを付けます。Bitbucket は 新規に作成したもの、ローカルは SVN リポジトリから移行して新規で作成されたものと祖先が違っているためです。

--allow-unrealted-histories を付けないで実行すると、refusing to merge unrelated histories になります。

$ git merge origin/master
fatal: refusing to merge unrelated histories

git push

–set-upstream origin master

現在作業している Gitリポジトリは、SVNから変換してローカルで作成したものなので、現在の作業ブランチから見た上流ブランチが存在していません。この上流ブランチを指定して git push してあげる必要があります。

–set-upstream を付けないとエラーになります

$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master

全てのタグを git push する

全てのブランチを git push する


サーバーの状況を確認する

ローカル環境での全ての push が完了したので、サーバーのタグとブランチの反映状況を確認します。

タグを確認する

master のドロップダウンを表示、Tags を表示して、タグが反映されていることを確認します。

ブランチを確認する

master のドロップダウンを表示、Branches を選択して、ブランチが反映されていることを確認します。

完了

以上で Bitbucket への移入は完了です。

コメント