Quick Tip: Bulk Update Github Repo Orgs

Quick Tips Jul 05 2019

I recently needed to rename a Github Organization with about 80 repositories. While Github helpfully creates automated redirects for your repos during the rename process, it is still best practice to go through and update the remote URLs for all repos you have cloned on your computer.

This is a pretty simple process for a single repository. You just need to set your remote URL to use the new Organization name (NewOrgName in this example).

> git remote set-url origin git@github.com:NewOrgName/my-repo.git

Note: This post assumes that your remote repo is named origin and you cloned via SSH, please adjust accordingly.

Now, if you are like me you probably have something like 50 repos that you'll need to perform this operation on. So instead of doing data entry for an hour, I put together this little bash one-liner that loops through my repos and performs the update.

for d in ./*/ ; do (cd "$d" && git remote set-url origin $(git remote get-url origin | sed s/:OldOrgName\\//:NewOrgName\\//) && echo "Remote Updated: $d"); done

A few notes about this script:

  • It loops through the direct children of your current directory and uses sed to replace the old org name with your new org name. This means your directory structure must look something like this for this to work:
- directory/
  - repo-1/
  - repo-2/
  - etc...
  • Make sure you update the OldOrgName and NewOrgName values to reflect your actual values.

← Back Home