gitのリモートリポジトリを変更したい
🤔 状況
- リポジトリ名を変えたい
- GitHubのユーザ名を変えた
👍 方法
git remote -v
で作業前後の対象確認を行いながら、git remote set-url [target_repository] [url]
で変更しましょう。
$ git remote -v
$ git remote set-url origin git@github.com:new_name/repository_name.git
git remote -v
🤩 たくさんのリポジトリを変更する方法
状況に合わせて、 sed -e 's/old_name/new_name/g'
を変更して置換しましょう。
また、remote -v
で複数サーバが設定されている場合は、grepをいい感じに設定してください。
echo "git remote set-url origin git@"$(git remote -v | grep fetch | cut -d ' ' -f 1 | cut -d '@' -f 2 | sed -e 's/old_name/new_name/g') | bash