Skip to content

Instantly share code, notes, and snippets.

@codeopensrc
Last active June 8, 2016 18:18
Show Gist options
  • Select an option

  • Save codeopensrc/e69e05b58647cb1d0e85fc98be2d2b4e to your computer and use it in GitHub Desktop.

Select an option

Save codeopensrc/e69e05b58647cb1d0e85fc98be2d2b4e to your computer and use it in GitHub Desktop.
Quickly serve folders/git repos to others privately
# Linux/Mac - No windows
# Quickly share your code/script with others that have ssh access to the same server.
# Include one or both functions inside your ~/.bash_aliases.
# `gitinitrepo` needs `gitserverepo`, otherwise it just inits a git repo
# To use, change the SERVER1, SERVER2, SHORTNAME1, SHORTNAME2 variables to whatever you want
# adding or removing if you want as well.
# Then inside the folder without a git repo attached
# `gitinitrepo myshortname`
# Or if its an existing git repo
# `gitserverepo myshortname2`
# Then give the users the outputted command
# You then can push/pull from this repo like github as well using `git [push, pull] myshortname master
# To serve an uninitialized folder as a git repo
function gitinitrepo () {
if [ -z "$@" ] ; then echo "No location specified, see bash_aliases" ; return; fi
git init
git add . && git commit -m "Init"
gitserverepo $@
}
# To serve a folder that has an existing git repo
function gitserverepo () {
REPO=${PWD##*/}
SERVER1=username@ipaddress:/path/to/work/git/folder
SERVER2=username@ipaddress:/path/to/personal/git/folder
SHORTNAME1="work"
SHORTNAME2="personal"
URL=""
if [ -z "$@" ] ; then echo "No location specified, see bash_aliases" ; return; fi
if [ "$@" = "$SHORTNAME1" ] ; then URL=$SERVER1 ; fi
if [ "$@" = "$SHORTNAME2" ] ; then URL=$SERVER2 ; fi
if [ -z "$URL" ] ; then echo "Not a valid shortname, see bash_aliasses" ; return; fi
git remote add $@ $URL/$REPO.git
cd ..
git clone --bare $REPO $REPO.git
rsync -avuz -e ssh $REPO.git $URL
rm -rf $REPO.git
cd $REPO
echo ""
echo "== New repo available: $REPO.git =="
echo ""
echo "== Provide below command to clone repo: =="
echo " git clone $URL/$REPO.git"
echo ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment