Last active
June 8, 2016 18:18
-
-
Save codeopensrc/e69e05b58647cb1d0e85fc98be2d2b4e to your computer and use it in GitHub Desktop.
Quickly serve folders/git repos to others privately
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
| # 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