LoginSignup
1

リモートリポジトリのURLを変更する

Last updated at Posted at 2020-07-09

目的

  • 現在のリモートリポジトリではない別のリモートリポジトリにpushする方法をまとめる

調査

  • 下記コマンドを実行してみて$ git remoteコマンドの使用方法を読んでみる。

    $ git remote --help
    
  • 今回の用途に合ったオプションを発見した。下記に先のコマンドの結果を抜粋した物を記載する。

    SYNOPSIS
       git remote [-v | --verbose]
       git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>
       git remote rename <old> <new>
       git remote remove <name>
       git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
       git remote set-branches [--add] <name> <branch>...
       git remote get-url [--push] [--all] <name>
       git remote set-url [--push] <name> <newurl> [<oldurl>]
       git remote set-url --add [--push] <name> <newurl>
       git remote set-url --delete [--push] <name> <url>
       git remote [-v | --verbose] show [-n] <name>...
       git remote prune [-n | --dry-run] <name>...
       git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
    ~中略~
    set-url
    Changes URLs for the remote. Sets first URL for remote <name> that matches regex <oldurl> (first URL if no <oldurl> is given) to <newurl>. If <oldurl> doesn't match any URL, an error occurs and
    nothing is changed.
    
    With --push, push URLs are manipulated instead of fetch URLs.
    
    With --add, instead of changing existing URLs, new URL is added.
    
    With --delete, instead of changing existing URLs, all URLs matching regex <url> are deleted for remote <name>. Trying to delete all non-push URLs is an error.
    
    Note that the push URL and the fetch URL, even though they can be set differently, must still refer to the same place. What you pushed to the push URL should be what you would see if you
    immediately fetched from the fetch URL. If you are trying to fetch from one place (e.g. your upstream) and push to another (e.g. your publishing repository), use two separate remotes.
    

確認

  • 下記を実行して既存のリモートリポジトリのURLを確認した。

    $ git remote -v
    
  • 下記を実行して変更後のリモートリポジトリのURLを設定する。

    $ git remote set-url --add originなどのリモートリポジトリの名前 変更後のリモートリポジトリのURL
    
  • fatal: No such remote '〇〇'なとが出る方は下記を実行する。

    $ git remote add originなどのリモートリポジトリの名前 変更後のリモートリポジトリのURL
    
  • 下記を実行して変更後のリモートリポジトリのURLを確認した。

    $ git remote -v
    
  • 筆者の環境ではリモートリポジトリのURLの変更が確認できた。

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