Created
October 22, 2011 07:43
-
-
Save mgilliam/1305747 to your computer and use it in GitHub Desktop.
Publish a repository w/ all branches and tags to Github.
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/bash | |
# | |
# Publish a repository - including all branches and tags - to Github, | |
# optionally specifying an organization to which the private repository | |
# belongs. | |
usage=$( | |
cat <<EOF | |
$0 [-f | -o <org>] <repo> | |
-f Force: If a remote exists, replace it. | |
-o org Name of the organization that owns the private repo. | |
EOF | |
) | |
# Defaults: | |
force_default= | |
org_default="" | |
repo_default="" | |
while getopts "fo:" OPTION ; do | |
case "$OPTION" in | |
f) | |
f=true | |
;; | |
o) | |
org="$OPTARG/" | |
esac | |
done | |
: ${f=$force_default} | |
: ${org=$org_default} | |
: ${target=$repo_default} | |
for last; do true; done | |
target=`echo $last | sed 's/\///'` | |
if [ -z $target ] ; then | |
echo "$usage" | |
exit 1 | |
fi | |
if [ -d "$target" ] && [ -d "$target/.git" ] ; then | |
cd "$target" >/dev/null 2>&1 | |
else | |
echo "No such directory or not a git repository." | |
exit 1 | |
fi | |
for remote in $(git remote) | |
do | |
if [ -n $remote ] ; then | |
if [ $f ] ; then | |
git remote rm $remote | |
else | |
echo "One or more remotes exist; use -f to replace." | |
exit 1 | |
fi | |
fi | |
done | |
git remote add origin [email protected]:$org$target.git | |
echo " | |
Publishing the master branch... | |
" | |
git push -u origin master | |
echo " | |
Publishing all branches... | |
" | |
git push origin --all | |
echo " | |
Publishing all tags... | |
" | |
git push --tags |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment