Skip to content

Instantly share code, notes, and snippets.

@mateusreis
Last active December 24, 2015 12:38
Show Gist options
  • Save mateusreis/6798769 to your computer and use it in GitHub Desktop.
Save mateusreis/6798769 to your computer and use it in GitHub Desktop.
Shell script that clones small framework.
#!/bin/bash
# em /usr/local/bin/
CURRENT=`pwd`
DIR=`basename $CURRENT`
echo " "
echo "html1 [branch] Clona um branch específico sem criar um repositório."
echo " "
echo " Ver lista de branchs em https://github.com/mateusreis/small.git"
echo " "
# checa se já existem arquivos no diretório
if [ "$(ls -A)" ]; then
echo 'Diretório não está vazio. Bye!'
exit 0
fi
# Checa se existe argumento
if [ -z "$1" ]; then
echo "Entre com o nome do branch:"
read BRANCH
branch=$BRANCH
else
branch=$1
fi
# checa se o branch existe
if ! git ls-remote https://github.com/mateusreis/small.git | grep $branch; then
echo "Branch inexistente. Bye!"
exit 0
fi
# clona o branch
if git clone -b $branch https://github.com/mateusreis/small.git .; then
echo "Branch clonado com sucesso... " $branch
else
echo "Erro no clone. Bye!"
fi
# Deleta o repositório .git
rm -Rf .git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment