Using Git, Stash and Dropbox to Manage Your Own Code

Sometimes I’m asked how I manage my own (PowerShell) code, in terms of version control, backups, portability etc. In this presentation I demonstrated how my PowerShell code is typically broken down into functions and then placed into modules. This allows me to make very generic code for granular tasks, typically either to plug a gap missing from the out-of-the-box cmdlets or maybe stringing a few of them together. As a consultant this enables me to build up a toolkit of functions for particular scenarios gained over various different experiences and use them in a modular fashion where needed for each particular project. However, once these number in the hundreds how do you manage them effectively? I need them to:

  • be easily available depending on where I am working
  • be backed up
  • track changes via version control, useful even if you are not working in a team developing code together - mostly so I can remember how or why I changed something :-)

So I’m going to run your through the system I have found that works for me. It uses the following components:

  • A Dropbox account to sync the code between different machines, be available to download via a web browser and also store the code outside of my home lab. This means I can get access to my functions pretty much wherever I am and whether I am using my own or a customer machine.
  • A Linux VM in my homelab to run Git and Atlassian Stash for version control - $10 for a 10 user license (free to try out for 30 days)
  • Atlassian SourceTree. Free Git client for Mac or Windows

[text] sudo apt-get install git-core [/text]

[text]

git –version perl –version

[/text]

[text]

java -version sudo apt-get purge openjdk* sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java7-installer java -version

[/text]

[text]

sudo mkdir /var/stash sudo mkdir /var/stash/install sudo mkdir /var/stash/home cd /var/stash/install sudo wget http://www.atlassian.com/software/stash/downloads/binary/atlassian-stash-2.11.4.tar.gz sudo tar zxf atlassian-stash-2.11.4.tar.gz

[/text]

Create a user account to run Stash under.

[text]

sudo /usr/sbin/useradd –create-home –home-dir /usr/local/stash –shell /bin/bash stash

[/text]

Set STASH_HOME in setenv.sh to /var/stash/home.

[text]

sudo vi atlassian-stash-2.11.4/bin/setenv.sh

[/text]

[text]

sudo chown -R stash /var/stash

[/text]

Start Stash.

[text]

/var/stash/install/atlassian-stash-2.11.4/bin/start-stash.sh

[/text]

  • Edit code directly on my laptop
  • Or copy code edited elsewhere and pop it in the Dropbox folder