Bash shell script to make another git repository project


You will need to be using an apple mac or ubuntu linux system to gain the most from this script. It should be possible to do this in windows, but as i do not have one, i can’t advise. The commands shown here are trial commands keyed into a terminal session running the bash shell. It assumes you have already followed part one of this guide to make a github repository named ‘sample’ on your github account.

The idea is to use bash commands to control a remote github system holding your repository. Comment lines below are preceded by double // characters, these lines are remarks that must NOT be keyed. Further comments may follow a command and you can tell these by looking for <–

You will also need the ‘git’ tool installed on your local system.

Note that the term ‘repo’ is a short term for repository – a storage area, typically for text, documents and source code.

// ————————————————–
// new script to make another git repository project
// go to github and make a repository called sample // you will need an SSH public/private security id set up in your keychain – google for this uif you do not already have a set of public/private SSH keys.

// Create a new project here….
// change into the directory of your choice on your local system
cd /Volumes/Media1/Software

// here i ask the remote github server for a full copy of my sample repository that i made in part one of this guide.
// the clone command will create a folder directory named ‘sample’, create some local metadata that git needs to function, and also create an alias name called ‘origin’. This alias name is just a short-cut way to avoid writing the full address of our git repository, like !
git clone

// change into the cloned folder
cd sample

//git init

// create an empty file for some of our documentation.
touch README

// edit and save some notes about this project – apple macs use the open command to start an editor session, forgot the ubuntu equivalent command
open -e README

// now we tell the local version control system, git in this case, to include the README file as an artifact to be controlled by git
git add README

// and we tell git that we are ready to mark the current environment as ready-to-go
git commit -m "initial commit"

// if you run git clone above, you will not need this command
git remote add origin

// time to tell git to send a full copy of our environment back to the github server for user and specifically for the storage facility named sample.git :
git push origin master

// we can construct a documentation area within our ‘sample’ repository. By default, this area is named ‘gh-pages’
// Create an own branch for the gh-pages
cd sample

git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx

// build a small index page, we can expand this later
echo "Hi Kids" >> index.html

// tell the local version control system to include all files, etc in the current directory named ‘.’
git add .

// and we tell git that we are ready to mark the current documentation as ready-to-go
git commit -a -m "my first gh-page"

// and here we send our whole document environment to the github server
git push origin gh-pages

// The index.html is empty. But it’s necessary to commit something to make the branch live. If not, you’ll have problems on the next step.

Check page online

Alright, after pushing your files you’re ready to check out the generated site online at an address like
where you replace my name with your github account name, and replace the name ‘sample’ with the name of the repo you built in part one of this guide.

. . .

i’m still working on this section of code as it does not work well just now, so would suggest you stop here and just review the code and links below.

// Add documentation as a submodule in master branch

Now we have two branches called master and gh-pages. The next step is to point the reference for the gh-pages branch to a subdir of master. See

Our submodule will then appear to be part of our hosted project at github.

git checkout master
git submodule add -b gh-pages _site
git status
git commit -m "added gh-pages as submodule"
git push

Git status reports a new .gitmodules file, with metadata about the submodules. And the _site directory we just specified. Now we initialize the sub-module and confirm it’s version:

git submodule init
git submodule
git status
cd _site
echo "Index Page for _site" >> index.html
git add .
git commit -m "site generated"
git push origin gh-pages
cd ..

// so back at root of project, commit again
git commit -a -m "build site"
git push origin master

// Now both branches should be pushed to github and master _site points to the up to date gh-pages as we would normally do.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s