Skip to content

Instantly share code, notes, and snippets.

@azat
Created March 17, 2013 21:39
Show Gist options
  • Save azat/5183769 to your computer and use it in GitHub Desktop.
Save azat/5183769 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# [git] convert repo to bare
#
set -e
if [ "$1" = "" ]; then
echo "Set directory"
exit 1
fi
REPO=$(readlink -f "$1")
if [ ! -d "$REPO" ]; then
echo "$REPO is not a directory"
exit 2
fi
if [ ! -d "$REPO/.git" ]; then
echo "$REPO already is bare"
exit
fi
BARE_FOLDER=$(mktemp -d --tmpdir=.)
cd "$REPO"
mv .git "../$BARE_FOLDER" && rm -fr *
mv ../$BARE_FOLDER/.git/* .
rmdir "../$BARE_FOLDER/.git"
rmdir "../$BARE_FOLDER"
git config --bool core.bare true
cd ..
# renaming just for clarity
if [[ ! "$REPO" == *".git" ]]; then
mv "$REPO" "$REPO.git"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment