Crie um repositório Github com Shell Script

Scripts shell para Git

Sobre

Scripts de shell para manipular seu repositório Git.

Uso

Baixe um script de shell que deseja usar em seu repositório git e, em seguida, adicione permissão para executar arquivos com os comandos abaixo.

$ chmod u+x init.sh

Lista

  • init.sh
  • commit.sh
  • push.sh
  • build.sh
  • github.sh

init.sh

  • git init
  • crio .gitignore
  • adicione o nome do arquivo a .gitignore

# define function
addToGitignore
() {

# add filename to .gitignore
echo
"(hit q for quit)"
while :
do

read
-p "Type file name to add to .gitignore: " filename
# quit when
if [ $filename = "q" ]
then
break
else
echo $filename
>> .gitignore
fi


done

}

# init
git init


# .gitignore
read
-p "Do you want to add .gitignore? (y/n)" answer


case $answer in
y
)
touch
.gitignore
addToGitignore

;;
n
)
;;
*)
;;
esac

commit.sh

  • apenas adicione todos os arquivos
  • commitar com mensagens de commit

# add
git add
-A

# commit
read
-p "Commit message: " commitMessage
git commit
-m "$commitMessage"

push.sh

  • commit.sh
  • + pode adicionar tag
  • + empurrar

# ( commit.sh... )

# add tag
read
-p "Do you want to add tag? (y/n)" answer

case $answer in
y
)
# show all tags
git tag

# add a new tag
read
-p "Tag Version: " tagVersion
read
-p "Tagging Message: " taggingMessage
git tag
-a $tagVersion -m "$taggingMessage"
git push
--tags
;;
n
)
;;
*)
;;
esac

# push
git push

build.sh

  • push.sh
  • + empurrar para gh-pagesramificar

# ( push.sh... )

# build
git checkout gh
-pages
git rebase master

git push origin gh
-pages
git checkout master

github.sh

  • criar um novo repo no Github
  • git init yoru diretório atual
  • git push para o repo recém-criado

#!/bin/sh
#
# github.sh
# - create a new repository in Github
#
# Copyright (C) 2015 Kenju - All Rights Reserved
# https://github.com/KENJU/git_shellscript

# get user name
username
=`git config github.user`
if [ "$username" = "" ]; then
echo
"Could not find username, run 'git config --global github.user <username>'"
invalid_credentials
=1
fi

# get repo name
dir_name
=`basename $(pwd)`
read
-p "Do you want to use '$dir_name' as a repo name?(y/n)" answer_dirname
case $answer_dirname in
y
)
# use currently dir name as a repo name
reponame
=$dir_name
;;
n
)
read
-p "Enter your new repository name: " reponame
if [ "$reponame" = "" ]; then
reponame
=$dir_name
fi
;;
*)
;;
esac


# create repo
echo
"Creating Github repository '$reponame' ..."
curl
-u $username https://api.github.com/user/repos -d '{"name":"'$reponame'"}'
echo
" done."

# create empty README.md
echo
"Creating README ..."
touch README
.md
echo
" done."

# push to remote repo
echo
"Pushing to remote ..."
git init

git add
-A
git commit
-m "first commit"
git remote rm origin

git remote add origin https
://github.com/$username/$reponame.git
git push
-u origin master
echo
" done."

# open in a browser
read
-p "Do you want to open the new repo page in browser?(y/n): " answer_browser

case $answer_browser in
y
)
echo
"Opening in a browser ..."
open https
://github.com/$username/$reponame
;;
n
)
;;
*)
;;
esac