【git remote set-url origin new url】リポジトリ先を変更する方法

Git


Warning: Undefined array key 2 in /home/god48/god48.com/public_html/wp-content/themes/luxech/functions.php on line 99

Warning: Undefined array key 4 in /home/god48/god48.com/public_html/wp-content/themes/luxech/functions.php on line 104

Warning: Undefined array key 6 in /home/god48/god48.com/public_html/wp-content/themes/luxech/functions.php on line 109
git

kamiです。

今回はGit cloneしてからcommitからpushなどのリポジトリ先を変える方法の紹介です。

現在のリモート先の確認

「git remote -v」コマンドで、現在設定されているリモートリポジトリを確認するコマンドです。

-v オプションは、リモート名とともにそのURLを表示します
(fetch と push 両方のURLが表示されます)。

git remote -v

git remote -vの結果

  • origin:リモートリポジトリの名前です。デフォルトでは origin という名前が付けられます。
  • fetch:URLはデータを取得する(fetch や pull)ときに使用されます。
  • push:URLはローカルの変更を送信する(push)ときに使用されます。
origin  https://github.com/company/hoge-appe.git (fetch)
origin  https://github.com/company/hoge-appe.git (push)

リモート先を変更

リモートリポジトリ origin のURLを変更します。
例えば、リモートリポジトリのURLを他のリポジトリに切り替えたり、HTTPSとSSHの切り替えをする際に使います。

git remote set-url origin <新しいURL>
git remote set-url origin https://github.com/company/foo-appe.git                               

URL変更後の結果

git remote set-url origin後のgit remote -vの結果です。

origin  https://github.com/company/foo-appe.git (fetch)
origin  https://github.com/company/foo-appe.git (push)

以上です

GitGit

Posted by kami