I frequently find myself needing to teach my friends git. This is the first in a series of n posts to quickly get you up to speed with git.
So why git?
There are two main reasons why I use version control: I like being able to save my work, and I like being able to work on things in parallel with other people and have software integrate the changes we make for me. I use git because, as a distributed version control system (more about that in a minute), it's easy for me to put anything on my machine under version control, and it's very good at merging things from other people if I'm not working alone.
In git, a collection of files under version control is called a repository. To save different versions of your work, you take snapshots, called commits. Here's how you create a new repository:
git init .
This will bring the current directory under version control. To make a commit, first, add the files you want to take a snapshot of:
git add foo.txt
Then, commit all the files you've marked for add:
git commit -m "adding foo.txt"
The "-m" sets the commit message. This should usually be more descriptive than the one I have here. After you make changes to foo.txt, or another file, you can rinse and repeat adding and committing to keep your changes saved!
So what does a commit do?
As I said earlier, a commit is essentially a snapshot of your work at a given time. In addition to storing what was changed in the files, a commit stores a few other notable pieces of information:
- the commit message
- the author name and email address
- the time of the commit
- the "parent" commit (ie. the previous commit)
- the SHA (hash) of the commit, which is based on the time, the author, and the parent commit, and uniquely identifies it
That's all for now! Tune in next week for branching and merging!