Git is great for version control and "backup" uses. If you want to access files from more than one computer, as you describe, the most pain-free way of getting a Git repository "up and running" is to use Github.com.
Github.com provides free space to host public Git repositories (it's geared towards open source software). With a paid plan (starting $7/month), Git will give you space for completely private repositories, which only you (or people you allow) can access.
Otherwise, you can install Git yourself on your own server, in which case I'd recommend you setup SSH keys and access your repo over SSH (for ease of configuration and security). On your server, you can go into the folder you want to store your repo in and setup an "empty" repo like this:
git init --bare
Then locally, you can add the location of this new repo by adding a git "remote" to your local codebase:
git remote add origin ssh://myserver.com:/var/repos/my_repo.git
Now you have an "origin" server, which you can push to/pull from at will.
Installing Git
If you're on Windows, you should install msysgit and accept the defaults (I like to enable the option for Git to be added to my right-click context menu). I then use the Git Bash command-line utility to use Git, but it comes with a basic GUI tool as well.
If you're on a Mac, you can download the Mac installer image and follow its instructions.
If you're on Linux, you can use your package manager to install git. On the most recent version of Ubuntu, for example, you'd run:
sudo apt-get install git
Using Git
There's an online Git Book and the git man pages, but here are some basics.
Make a folder "git-enabled":
git init
Add all of your current files in this folder to git's version control:
git add .
Commit these files to your local Git "staging area":
git commit -m "My first commit message"
When you're ready, you can push this local staging area to a remote repo, like github or your own server (assumes you already have a remote called "origin" setup, see above):
git push origin master
Which pushes the default "master" branch out to your remote repo. If you need to update your local copy with files from your remote repo's master branch, do a "pull" instead:
git pull origin master
Whenever you do new work, you want to create a branch and work there, so you don't muddle the master branch, and so you can merge your changes once you know they're working. So...
To create a new branch and start working in it, you can "checkout" the branch and create it simultaneously with the following:
git checkout -b new_branch
When you're done in new_branch
, checkout the master branch again and merge your changes:
git checkout master
git merge new_branch
If you want to see a diff of the two branches before merging, use the git diff
command:
git diff master new_branch
To see a log of all your commit, use git log
:
git log
Press 'q' to exit the log view.
In any given day, those are the commands I use most.