LoginSignup
2
2

More than 3 years have passed since last update.

ローカルのGitリポジトリをGItHub等他サービスに丸ごと移植する

Posted at

はじめに

最近のGitHub等Gitサービスはとても高機能になっており、Wikiやsnipetでのノウハウシェア、CI/CDとの連携、issue作成によるタスク管理等開発に役立つ機能が満載です。更に大抵はrepositoryを作成する際に既存repositoryのimportが出来るようになっています。とても便利

ただ、こういったリポジトリの移行をしたいプロジェクトというのは、意外に外部公開していないリポジトリを使用していたりするため、 サービスが提供しているimport機能が使えない! ということが多々あります。なので、ローカルサーバーからもimportする方法をまとめました。
(他サービスに fork する感じ)

スクリプト

github.com/developer-kikikaikai/import_repository にLinux/Macで使えるスクリプトを作りました。使い方は以下

  1. import先のリポジトリを作成しておく。
  2. servers.json にimport元と先のrepository urlを(repository名除く)記載する。
  3. ./import_on_unix.sh  import元repository import先repository

元repositoryの全branch、tagをimportします。default branchはmasterに設定しています。

例えば ssh://localserver/repos/sample_local.gitgithub.com/developer-kikikaikai/sample_github.git に移植する場合は、

  1. GitHubの+ -> New repository でsample_github.gitを作成
  2. servers.jsonをアップデート
  3. ./import_on_unix.sh sample_local.git sample_github.git
servers.json
{
        "src": "ssh://localserver/repos",
        "dist": "git@github.com:developer-kikikaikai"
}

これだけ。

実際にやること

こんなイメージです。remoteのrepositoryを git remote add で追加して、元からfetch -> 先にpushする感じ
repos.png

git remote add で対象のリポジトリを登録する。

git remote add srctag ssh://localserver/repos/sample_local.git
git remote add disttag github.com/developer-kikikaikai/sample_github.git

git fetch でbranch, tagを取得する

git remote add で設定した名前を指定することで、登録したrepositoryのbranch, tagが取得できます。

git fetch srctag 

git fetch で落としてきたbranchをpushする

git fetch はremoteのbranch情報を取得しただけでlocal環境にはまだbranchが出来ていません。なのでまずbranchを作成します。

git branch local_branch_name srctag/remote_branch_name

後はbranchをpushするだけ。: でくくると localのbranch名:remote側にpushするbranch名という指定に使えます。

git push disttag local_branch_name:remote_branch_name

git fetch で落としてきたtagをpushする

tagは --tags でまとめてpush出来ます。

git push ${DISTTAG} --tags

参考

Gitのイメージをつかむのに使えます: GitとGitHub用語について、改正してデジ絵にしました!
丸っとimportならこんな感じでシンプル: Gitリポジトリの中身を、ブランチとタグも含めて別リポジトリにコピーする
tagのpush git で branch を push しただけじゃ tag は push されない話

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2