Skip to content

Instantly share code, notes, and snippets.

@argon
Created July 14, 2011 10:28
Show Gist options
  • Save argon/1082235 to your computer and use it in GitHub Desktop.
Save argon/1082235 to your computer and use it in GitHub Desktop.
Shell script to create a detached working directory
#!/bin/bash
if [ $# -lt 2 ]
then
echo "usage error: $0 <git dir> <work tree>"
exit 1;
fi
CWD=`pwd`
if [ ! -d $1 ]
then
mkdir $1;
fi
cd $1;
D1=`pwd`
cd $CWD;
if [ ! -d $2 ]
then
mkdir $2;
echo "Created worktree at: $2"
fi
cd $2;
D2=`pwd`
cd $D1
git status &> /dev/null
if [ ! $? -eq 128 ]
then
echo "$1 is already an initialised git tree";
exit 1;
fi
git init --bare
git config core.worktree $D2
echo "Configured work tree at "$D2
git config core.bare false
git config receive.denycurrentbranch ignore
echo "#!/bin/sh" > hooks/post-receive
echo "git checkout -f" >> hooks/post-receive
chmod +x hooks/post-receive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment