Created
October 11, 2010 17:57
-
-
Save mikewest/620949 to your computer and use it in GitHub Desktop.
"Oneliner" to backup your public github repos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Run from a directory in which you'd like to shove a _lot_ of bare repositories. | |
curl -s http://github.com/api/v2/yaml/repos/show/mikewest | grep ':url:' | awk '{ print $2 }' | sed -e 's#http://#git://#' -e 's#$#.git#' | xargs -L 1 git clone --bare |
I don't believe "git clone" will overwrite an existing local directory, so this won't work unless you run it in an empty directory or remove the local (*.git) directories from a previous run first.
Also, the grep and awk commands are unnecessary... it can be done with a single sed command:
cd [backup directory]
rm -rf _.git
curl -s [URL] | sed -n '/^ *:url:/ s/ *:url: *http:(._)/git:\1.git/p' | xargs -L 1 git clone --bare
In fact... it can be done without xargs as well.... just pipe to a shell, eg:
cd [backup directory]
rm -rf *.git
curl -s [URL] | sed -n '/^ *:url:/ s/ *:url: *http:\(.*\)/git clone --bare git:\1.git/p' | sh
aolcm: You're right. You can do everything with a single sed
command. :)
I find it pretty hard to follow, though... using smaller steps makes the whole process a bit clearer to me; I know exactly what each command is doing and can follow the interactions. I think your solution, though surely functional, is simply less readable.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can pass multiple -e commands to sed. Err, nvm.