Skip to content

Instantly share code, notes, and snippets.

@j4k
Created October 30, 2014 09:58
Show Gist options
  • Select an option

  • Save j4k/00460137a1ed3abbbb51 to your computer and use it in GitHub Desktop.

Select an option

Save j4k/00460137a1ed3abbbb51 to your computer and use it in GitHub Desktop.
batch remote alter git remotes from base directory
#!/bin/bash
for gitdir in `find ./ -name .git`;
do
workdir=${gitdir%/*};
echo;
reponame=$(basename $(git --git-dir=$gitdir remote show -n origin | grep Fetch | cut -d: -f2-));
echo $reponame;
neworigin="git@[REPLACE_WITH_URL]/$reponame";
echo $neworigin;
git --git-dir=$gitdir --work-tree=$workdir remote remove origin;
git --git-dir=$gitdir --work-tree=$workdir remote add origin $neworigin;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment