Skip to content

Instantly share code, notes, and snippets.

@sipofwater
Last active August 8, 2019 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sipofwater/2732ad59dad0ccb72e1fd25e6c055ee7 to your computer and use it in GitHub Desktop.
Save sipofwater/2732ad59dad0ccb72e1fd25e6c055ee7 to your computer and use it in GitHub Desktop.

The Purpose of githubinit.sh

is to automate the ....

asumptions

  • initializing current directory

dependencies required

usage

  • sh githubinit.sh <projectname>

The <projectname> will be used to:

  • create a <projectname> directory under /web/webroot/
  • add the DNS HOSTS entry to resolve http://<projectname> locally

sh githubinit.sh <reponame>

  • takes 1 input parameter <reponame> (which should match <projectname>)
  • if does not exist, creates <reponame> directory
  • if does not exist, copies default <README.md>
  • if does not exist, creates <reponame> on gitHub and adds remote origin
  • initializes repo and pushes to github master
  • creates develop branch, adds files, and pushes upstream, setting tracking, and removing local master branch
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment