LoginSignup
3
1

More than 3 years have passed since last update.

リポジトリをまたがったタグやブランチの複製

Posted at

Gitで別リポジトリのタグやブランチを複製したときの備忘録

やりたいこと

  • リポジトリ(src)の特定のタグ(version1.0)を、別リポジトリ(dst)のブランチ(edit_version1.0)として複製する
  • リポジトリ(src)の特定のブランチ(edit_version1.0)を、別リポジトリ(dst)のタグ(version1.0)として複製する

手順

リポジトリ(dst)をクローンし、複製先となるローカルブランチ(edit_version1.0)を作成

git clone https://github.com/dst.git
cd dst
git checkout --orphan edit_version1.0
git reset --hard

リモートリポジトリ(tmp)として、リポジトリ(src)を登録

git remote add tmp https://github.com/src.git

リポジトリ(src)から特定のタグorブランチをプル

※タグをプルする場合
git pull tmp version1.0 --allow-unrelated-histories

※ブランチをプルする場合
git pull tmp edit_version1.0 --allow-unrelated-histories

リポジトリ(dst)へプッシュ

※タグ(version1.0)を付ける場合のみ実施
git tag version1.0

git remote rm tmp

※タグ(version1.0)をプッシュする場合
git push origin version1.0

※ブランチ(edit_version1.0)をプッシュする場合
git push origin edit_version1.0

作業ディレクトリの削除

cd ..
rm -rf dst

参考

  • リモートリポジトリのタグの削除
git push --delete origin タグ名
3
1
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
3
1