13
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

HerokuのGitリポジトリと別のリモートGitリポジトリを関連付ける

Last updated at Posted at 2013-02-26

手順としては下記のようにやればよい。
Heroku にある Git リポジトリを楽に remote に設定する

  1. リモートリポジトリからgit clone
  2. heroku app作成
  3. herokuのリモートリポジトリも追加する
$ git remote add heroku git@heroku.com:APPNAME.git

または

$ heroku git:remote --app APPNAME

以降、pushしたいときは以下のようにする。

$ git push heroku master
$ git push origin master

ここで、個人的に間違った手順でいままでやっていたことに気づく…

やらかしたこと:

  1. リモートリポジトリからgit clone
  2. ローカルリポジトリで.git以下を消去して
  3. git initしてherokuにpushしてた

なので、herokuともう一個別のリモートリポジトリも使うための方法を探ったら以下のようになった。ちなみにリモートリポジトリがbitucketの場合。

$ git remote add origin git@bitbucket.org:YOUR_ACCOUNT/REPOSITORY.git

参考

ローカルの既存のgitリポジトリをbitbucketに放り込む方法
git remote 使い方


リモートのリポジトリを変更したい場合

リモートのリポジトリ名を変更したい場合(そんなケースある?)は下記のとおりに。

$ git remote
hoge
origin

# リモートリポジトリ hoge から fuga に変更
$ git remote rename hoge fuga
$ git remote
fuga
origin

リポジトリ名はそのままにしたくてリポジトリのURLを変更したい場合は、結局よくわからなくて一旦削除してから追加したらできた。(もっといいやりかたあったら教えてください…)

$ git remote -v

hoge  git@hoge.com:hoge.git (fetch)
hoge  git@hoge.com:hoge.git (push)
origin  git@abc.org:xyz/hoge.git (fetch)
origin  git@abc.org:xyz/hoge.git (push)

# リモートリポジトリを一旦削除して、fuga.git を追加
$ git remote rm hoge
$ git remote add hoge git@hoge.com:fuga.git
$ git remote -v

hoge  git@hoge.com:fuga.git (fetch)
hoge  git@hoge.com:fuga.git (push)
origin  git@abc.org:xyz/hoge.git (fetch)
origin  git@abc.org:xyz/hoge.git (push)
13
16
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
13
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?