1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitでリポジトリURLを置き換える方法

Last updated at Posted at 2024-11-12

はじめに

 Gitで、リポジトリURLを置き換えたい際の設定方法を紹介する。この方法を使うと、Gitリポジトリの移管などで、リモートリポジトリURLが変更された場合に有効。

方法

Git Configコマンドで設定する。

グローバルに設定する場合(--globalオプション)

git config --global url.{after_url}.insteadOf {before_url}
  • {after_url} : 置き換え後のURL
  • {before_url} : 置き換え前のURL

例: GitLabからGitHubへの置き換え

git config --global url."https://github.com/".insteadOf "https://gitlab.com/"

ポイント
置き換えたいURLのみ記載する(Organization名など)

以下のコマンドで確認することができる。

cat ~/.gitconfig

結果例

[url "https://github.com/"]
    insteadOf = https://gitlab.com/

複数のURLを1つのURLに置き換えたい場合

グローバルに設定する場合(--globalオプション)

git config --global --add url.{after_url}.insteadOf {before_url}
  • --addを使うと追記可能

例: GitLabおよびBitbucketからGitHubへの置き換え

git config --global url."https://github.com/".insteadOf "https://gitlab.com/"
git config --global --add url."https://github.com/".insteadOf "https://bitbucket.org/"

結果例

[url "https://github.com/"]
    insteadOf = https://gitlab.com/
    insteadOf = https://bitbucket.org/

まとめ

 Git Configを使い、GitでリポジトリURLを置き換える方法を紹介した。複数のリポジトリURLを1つのURLに置き換える方法も併せて紹介した。Gitリポジトリの移管などで、リモートリポジトリURLが変更された場合に有効。

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?