"git"

Git is really handy for publishing and sharing code. I found it a little difficult to get into, so here's a script that demonstrates a method (maybe not the best method, but it works for me) of managing a repository in Git. It doesn't have any branching or fancy stuff, but I don't need that right now.

This example code assumes you have set up your account at github.com and created repositories through the web interface and dealt with the new token string authentication stuff. Creating repositories through the web interface is handy because it lets you specify the license you want with just a couple of clicks. Oh - and, you want to create the minimal README.md file in the web interface, because this script updates that file to demonstrate that the pushes actually work.

#!/bin/bash # # hammer script to try to get some kind of # repeatable pattern with git operations cd /your/git-workspace # directory that contains repo directories if [ -z "$1" ] then echo "Usage: $0 repository" echo "Available repositories: " find . -maxdepth 1 -type d -printf "%f " | sed 's/\.git//' | sed 's/^\. //' echo " " exit else echo "Trying to push to $1" fi TARGET=$1 rm -rf $TARGET # this BLOWS AWAY anything you had in that repo directory git clone https://[YOUR-SECURITY-TOKEN]@github.com/YOUR-GIT-ID/$TARGET cd $TARGET DATESTRING=`date` echo "First push of this sequence: $DATESTRING" >> README.md git add README.md git status git commit -m "Committing first push of $DATESTRING" git push echo "OK, so much for the first push. Now, let's try a second push.." echo "Second push of this sequence: $DATESTRING" >> README.md git add README.md git status git commit -m "Committing second push of $DATESTRING" git push