Skip to content

Instantly share code, notes, and snippets.

@alexrah
Last active August 29, 2015 13:58
Show Gist options
  • Save alexrah/9944471 to your computer and use it in GitHub Desktop.
Save alexrah/9944471 to your computer and use it in GitHub Desktop.
automate mirror remotes: bash script checking between GitHub & Gitorious and then adding the missing remote to .git/config
#!/bin/bash
repos=.git/config
gito=`grep 'gitorious' .git/config`
hub=`grep 'github' .git/config`
if [ -n "$1" ]
then
if [ -n "$gito" ]
then
echo "Gitorius already mirrored."
else
echo '[remote "gitorious"]' >> $repos
echo "url = git@gitorious.org:alexrah/$1.git" >> $repos
echo "fetch = +refs/heads/*:refs/remotes/gitorious/*" >> $repos
echo "Added $1 mirror to Gitorious."
fi
if [ -n "$hub" ]
then
echo "GitHub already mirrored"
else
echo '[remote "github"]' >> $repos
echo "url = https://alexrah@github.com/alexrah/$1.git" >> $repos
echo "fetch = +refs/heads/*:refs/remotes/github/*" >> $repos
echo "Added $1 mirror to GitHub."
fi
else
echo "===================* HELP * ===================="
echo ""
echo "Plese enter the Repository Name,"
echo "es. sh remotes.sh RepoName"
echo ""
echo "This script check which remote is origin and"
echo "add GitHub or Gitorious as mirror."
echo 'then check with "git remote show"'
fi
@alexrah
Copy link
Author

alexrah commented Apr 2, 2014

For portability:

  1. change username in GitHub
  2. change project in Gitorious

Performance:

  1. firing 2 times "grep" doesn't seem very efficient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment