DEV Community

n350071🇯🇵
n350071🇯🇵

Posted on

[git] change remote repository url

🤔 Situation

  • changed remote repository url
  • changed GitHub user name

👍 Solution for a few repositories

git remote -v
git remote set-url origin git@github.com:new_name/repository_name.git
git remote -v
Enter fullscreen mode Exit fullscreen mode

🦄 Solution for many repositories

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
Enter fullscreen mode Exit fullscreen mode

If remote -v shows multiple remote repositories, i.e. origin, github, gitlab.., please adjust the grep command.

🔗 Parent Note

Top comments (0)