LoginSignup
93
78

More than 5 years have passed since last update.

リモートリポジトリを複数設定にする方法

Last updated at Posted at 2018-12-14

今回は1つのローカルリポジトリに対して、2つのリモートリポジトリを登録する方法についてご紹介したいと思います。

設定方法がとても簡単だったので、自分用として記録します。

現在のリポジトリを確認

git remote -v
origin  git@bitbucket.org:hogehoge/hoge.git (fetch)
origin  git@bitbucket.org:hogehoge/hoge.git (push)

上記を実行することで、現在設定されているリモートリポジトリを確認することが出来ます。

ここでリポジトリが2つ以上出てきたら、複数設定されているということになります。

現在は bitbucketしか表示されていませんね。

リモートリポジトリの追加

では、新たに登録したいリモートリポジトリを作成したら、

git remote add foofoo git@github.com:redamoon/foofoo.git

を実行。

fooに入るのはラベルと言って、自分が覚えやすい、管理しやすいもので構いません。

私は新たにGit hubのリモートリポジトリを追加したので

git remote add github git@github.com:redamoon/foofoo.git

としました。ここはお好みで!

これで2つのリモートリポジトリが作れちゃいました。

後は最初に打った、git remote -vで確認してみると

git remote -v
github  https://github.com/git@github.com:redamoon/foofoo.git (fetch)
github  https://github.com/git@github.com:redamoon/foofoo.git (push)
origin  git@bitbucket.org:hogehoge/hoge.git (fetch)
origin  git@bitbucket.org:hogehoge/hoge.git (push)

となり、設定されているはずです。

それぞれのリポジトリに対してpushする方法

pushをするにはそれぞれのリモートリポジトリのラベルを指定してあげれば大丈夫です。

git push origin master
git push foofoo master

こんな感じですね!

 【参考記事】
https://git-scm.com/book/ja/v2/Git-%E3%81%AE%E5%9F%BA%E6%9C%AC-%E3%83%AA%E3%83%A2%E3%83%BC%E3%83%88%E3%81%A7%E3%81%AE%E4%BD%9C%E6%A5%AD

93
78
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
93
78