Skip to content

Instantly share code, notes, and snippets.

@alexanderankin
Created April 16, 2017 21:14
Show Gist options
  • Select an option

  • Save alexanderankin/f7990e96ccd09e040a03d702f26f7661 to your computer and use it in GitHub Desktop.

Select an option

Save alexanderankin/f7990e96ccd09e040a03d702f26f7661 to your computer and use it in GitHub Desktop.
My Git Frontend
#!/bin/bash
alias wanip='dig +short myip.opendns.com @resolver1.opendns.com'
project_name=$1
bare_rep_dir="/home/`whoami`/bare-git/${project_name}" # bare repo directory
work_rep_dir="/home/`whoami`/my-apps/${project_name}" # working dir w/files
if [[ -d $bare_rep_dir && \
! -L $bare_rep_dir ]] ; then
echo "Already exists in $bare_rep_dir"
exit 1
fi
#exit
#Create a bare GIT repository:
mkdir -p "$bare_rep_dir" && pushd "$bare_rep_dir"
git init --bare
#Create a detached work tree:
mkdir -p "$work_rep_dir"
git config core.bare false
git config core.worktree "$work_rep_dir"
git config receive.denycurrentbranch ignore
#Force checkout on receive
prhook_file=$bare_rep_dir/hooks/post-receive
cat << EOF > "$prhook_file"
#!/bin/sh
git checkout -f
EOF
chmod +x "$prhook_file"
#Give msg to user
msg_prefix=ssh://`wanip`/~/bare-git/
echo
echo You can use this repository by entering the following commands:
echo
echo "git init $project_name && cd $project_name"
echo git remote add origin ${msg_prefix}$project_name
echo
echo The remote is:
echo ${msg_prefix}$project_name
echo
echo The working directory is:
echo $work_rep_dir
popd
@alexanderankin

Copy link
Copy Markdown
Author

inspiration creds: motherfucking website.

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