LoginSignup
1
0

More than 5 years have passed since last update.

git で特定のブランチだけ複数のリモートリポジトリに push する

Posted at

経緯

普段プライベートリポジトリで開発しているものを,master ブランチだけ公開したくなりました.

編集

もっとスマートな方法があるのかもしれませんが,以下のように .git/config を編集したらできました.
[remote "public"] を定義し,push 先の URL を複数指定しています.

Before

.git/config
...
[remote "origin"]
    url = https://github.com/<private repository>/hoge.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "develop"]
    remote = origin
    merge = refs/heads/develop
...

After

.git/config
 ...
 [remote "origin"]
     url = https://github.com/<private repository>/hoge.git
     fetch = +refs/heads/*:refs/remotes/origin/*
+[remote "public"]
+    url = https://github.com/<private repository>/hoge.git
+    url = https://github.com/<public repository>/hoge.git
+    fetch = +refs/heads/*:refs/remotes/origin/*
 [branch "master"]
-    remote = origin
+    remote = public
     merge = refs/heads/master
 [branch "develop"]
     remote = origin
     merge = refs/heads/develop
 ...

まとめ

.git/config を編集すると,複数リポジトリに push することができます.
これ以外にもブランチごとに様々な設定ができそうです.

1
0
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
1
0