|
#!/bin/bash |
|
set -x # echo on |
|
|
|
# Created: April 3, 2017 |
|
# Updated: April 21, 2017 |
|
# Purpose: Setup local git repo with gitHub repo for easy developer workflow. |
|
# Input: Program takes 1 input parameter of the gitHub repo name. |
|
|
|
gituser="sipofwater" |
|
repo=$1 |
|
origin="https://github.com/${gituser}/${repo}.git" |
|
# GITDIRECTORY=".git" |
|
PROJDIRECTORY="/web/webroot/${repo}/" |
|
GITREPOSITORY="/web/webroot/${repo}/.git" |
|
|
|
|
|
# create project folder if absent |
|
if [ -d $PROJDIRECTORY ]; then |
|
echo "Project directory exists"; |
|
else |
|
echo "Creating project directory..."; |
|
mkdir $PROJDIRECTORY |
|
fi |
|
|
|
cd $PROJDIRECTORY |
|
|
|
if [ -f "${PROJDIRECTORY}README.md" ]; then |
|
echo "Default README.md file exists."; |
|
else |
|
echo "Copying default README.md file..."; |
|
cp /web/scripts/includes/README.md $PROJDIRECTORY |
|
fi |
|
|
|
# create gitHub repository |
|
## dirty, should check if exists first, accepting error message for now |
|
curl -u "${gituser}" https://api.github.com/user/repos -d "{\"name\":\""${repo}"\", \"description\": \"\", \"private\": true, \"has_issues\": true, \"has_downloads\": true, \"has_wiki\": false}" |
|
|
|
# git init if .git absent |
|
if [ -d $GITREPOSITORY ]; then |
|
echo "git repo exists."; |
|
else |
|
echo "There is no .git repo. Initializing..."; |
|
git init |
|
fi |
|
|
|
# adding remote origin to github repo we created |
|
git remote add origin ${origin} |
|
|
|
# initial commit and push to github |
|
git add . |
|
git commit -m \"Initializing\" |
|
git push -u origin master |
|
|
|
# Create develop branch, add files and push upstream, setting tracking |
|
git checkout -b develop |
|
git add . |
|
git commit -m \"Initializing\" |
|
git push --set-upstream origin develop |
|
|
|
# deleting the LOCAL master branch since it's not needed LOCALLY |
|
git branch -d master |
|
|
|
# git remote show origin |
|
git remote show origin |
|
|
|
git remote -v |