I’m not sure about you, but losing code terrifies me. I save at a paranoid rate, and sometimes wonder “What if my computer spontaneously combusted right at this moment? How would I retrieve all the awesome code I’m writing?!”
My solution: Dropbox. It works perfectly as a remote repository for my code, giving me not only the ability to hit my code from multiple machines, but peace of mind. So I could just store my code directly in a Dropbox folder right? You could, but you then lose the ability to work with someone else if need be. Plus, constantly syncing to Dropbox is a bit annoying.
Second solution: Dropbox and Git. Now, I can work on a local repository, and push/pull from the remote when I need to. I have the ability to collaborate with others, view version history locally, as well as all the goodies in the previous paragraph.
~/project $ git init
First, head into your project directory and initialize a git repo. This will add all the hidden git goodness.
~/project $ git add .
Add the files to the Git index.
~/project $ git commit -m "Initial commit."
Setup your first commit to your git repository. The -m option denotes that you are adding a commit message, which will be what comes next in quotes. This will give you a window into what you changed during each commit.
~/project $ cd ~/Dropbox/gitRepos
~/Dropbox/gitRepos $ git init --bare project.git
Move to your Dropbox location to store Git repos. This can be any directory you setup in Dropbox. In here, initialize a bare repository. You can name it whatever you want, but it will need the git extension at the end. This will serve as your remote repository to push code to.
~/Dropbox/gitRepos $ cd ~/project
~/project $ git remote add dropbox ~/Dropbox/git/project.git
Head back into your project folder and add a remote target to Git. This will give us a remote named ‘dropbox’ to push our code to when we are ready.
~/project $ git push -u dropbox master
Push your first bit of code to your remote Dropbox repo! The -u option sets your upstream tracking reference. This means that in the future, you can just run git push, and the system will know what to do.
Woohoo! We’re all backed up in Dropbox, and using version control. If you are really lazy like I am, you can also setup a post-commit hook, so that after each commit git will do a push to Dropbox for you. I only use this for projects where I’m working alone though, as you run into conflicts with other developers.
If you have any questions, feel free to comment. You can also read more about this in my Github repo.