Created
April 5, 2016 16:27
-
-
Save RandyMcMillan/6ec296fae8d75c24a02734924a281576 to your computer and use it in GitHub Desktop.
Useful functions for using a remote git server
This file contains 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
# add to your .aliases file | |
#ssh to your git server | |
#MUST HAVE A USER NAMES "git" | |
#REFERENCE --> http://www.tomdalling.com/blog/software-processes/how-to-set-up-a-secure-git-server-at-home-osx/ | |
ip='###.###.###.###' | |
user='git' | |
alias deepspace='ssh $user@$ip' | |
alias ds=deepspace | |
alias lsds='ssh git@###.###.###.### "ls"' | |
#return local foldername | |
function folderName(){ | |
dest=$PWD; | |
f="${dest##*/}"; | |
echo "${f}" | |
} | |
alias fn=folderName | |
#makeRemote | |
function makeRemote(){ | |
dest=$PWD".git"; | |
f="${dest##*/}"; | |
ssh git@###.###.###.### "git init --bare ${f}"; | |
} | |
alias makeremote=makeRemote | |
alias mr=makeremote | |
#testRemote | |
function testRemote(){ | |
dest=$PWD".git"; | |
echo $dest; | |
f="${dest##*/}"; | |
git ls-remote ssh://git@###.###.###.###/Users/git/${f} &>- | |
if [ "$?" -ne 0 ]; then | |
echo "[ERROR] Unable to read from " git ls-remote ssh://git@###.###.###.###/Users/git/${f} | |
else | |
return "$?" | |
fi | |
} | |
alias testremote=testRemote | |
alias tr=testremote | |
#forceOrigin | |
function forceOrigin(){ | |
dest=$PWD".git"; | |
f="${dest##*/}"; | |
git ls-remote --get-url ssh://git@###.###.###.###/Users/git/${f} #&>- | |
if [ "$?" -ne 0 ]; #fail test | |
then | |
git remote -v | |
echo failed to read remote | |
makeRemote;forceOrigin; | |
else | |
echo succeeded to read | |
echo adding remote deepspace repository | |
git remote add deepspace ssh://git@###.###.###.###/Users/git/${f}; | |
echo setting remote url | |
git remote set-url --origin ssh://git@###.###.###.###/Users/git/${f}; | |
git remote -v | |
fi | |
git ls-remote --get-url https://github.com/USERNAME/${f} #&>- | |
if [ "$?" -ne 0 ]; #fail test | |
then | |
git remote -v | |
echo failed to read remote | |
makeRemote;forceOrigin; | |
else | |
echo succeeded to read | |
echo adding remote github repository | |
git remote add github https://github.com/USERNAME/${f}; | |
echo setting remote url | |
git remote set-url --addurl origin ssh://git@###.###.###.###/Users/git/${f}; | |
git remote -v | |
fi | |
} | |
alias forceorigin=forceOrigin | |
alias fo=forceorigin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment