akishin999の日記

調べた事などを書いて行きます。

Git リポジトリを GitLab へ移行した

自宅の LAN 内に GitLab サーバを立てたので、古い git リポジトリとかを移行しました。
またそのうちやるかも知れないので備忘録としてメモしておきます。

移行先リポジトリの作成

まずは GitLab 上に移行先となるリポジトリを作成しておきます。


リモートリポジトリの変更

ローカルに clone してあった移行対象リポジトリの参照先リモートリポジトリを確認。

>cd example
>git remote -v
origin  ssh://akishin@192.0.2.1/usr/local/git/example.git (fetch)
origin  ssh://akishin@192.0.2.1/usr/local/git/example.git (push)

現在は旧リモートリポジトリを参照しているので、参照先を削除します。

>git remote rm origin
>git remote -v

先ほど GitLab 上に作成したリポジトリの URL を参照先として追加します。

>git remote add origin git@192.0.2.5:akishin/example.git

追加できたことを確認。

>git remote -v
origin  git@192.0.2.5:akishin/example.git (fetch)
origin  git@192.0.2.5:akishin/example.git (push)

リモートへ push

問題なければリモートに push します。

>git push -u origin master
Counting objects: 2731, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (1686/1686), done.
Writing objects: 100% (2731/2731), 4.86 MiB | 147 KiB/s, done.
Total 2731 (delta 748), reused 2731 (delta 748)
To git@192.0.2.5:akishin/example.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

GitLab 上でちゃんと push されていることが確認できます。
当然ですが git なのでそれまでの履歴も GitLab 上で見る事ができます。

たったこれだけで手元の git リポジトリを GitLab での管理に移行できました。
GitLab あまり関係ないけど git だとリポジトリの移行が楽なのが嬉しい。