Why is it awesome?
- Track changes.
- Never lose code again. Seriously.
- Revert stuff when you dick it.
- Collaborate as part of a team, without conflict, even when working on the same file(s).
- Deploy stuff easily, and without having to remember what you've changed.
- Open-Source your projects, look awesome.
- Make something cool, open, and encourage contribution, free code.
- Every agency ever uses it. If they don't. They're doing it wrong.
What are the options?
-
Subversion (SVN)
- A bit legacy, likes to break and yell TREE CONFLICT at your face.
- Still used for major codebases like Wordpress and the Symfony Project.
- The majority are migrating away from it. But it's still useful if you want to contribute or utilise the above.
-
Git
- Distributed.
- Pretty hard to dick.
- Quite approachable.
- Github.
-
Mercurial
- Distributed.
- Looks cool.
- Supported by Github also.
- Considered it when migrating away from SVN at work.. went with Git.
So how do I use it?
Command line will always be the fastest way, and isn't too scary once you've got used to it.
If you're on a Mac; Git Tower looks cool pretty. Don't ask me how to use it though; I'd be guessing.
Repository
.git
Staging Area
Every file change that you want to commit goes into the staging area at some point. Adding or removing puts stuff in the staging area. You can see what's in it when you do 'git status'.
You can dynamically stage stuff and commit it all at once by adding the 'a' flag to your commit:
git commit –am "Blah blah added some new buttons and stuff."
That would commit all the files that git already knows about that have changed (so no untracked files).
You also don't have to commit the whole stage at once. You can add file paths (space-delimitated) to most commands:
git commit –m "OMG some images!" images/flowers/* images/trees images/logo.png
Some scenarios
I've added a feature, and nothing else, all these files need to go up!
git add . // Unix basics, '.' Remember?
git status // Check what's going up
git commit –m "My awesome new feature that does x. YAY."
Done.
git commit –m "I made some changes to the config and junk." includes/config.php
Done.
I want my code on Github so people see it and think "WOW, YOU'RE AWESOME"
Having committed some stuff. Push.
Argh I need to configure Github!
Note: You'll need to copy an SSH public key from your environment to Github, so that it knows it's yours and its okay to accept code from it.
How?
help.github.com/win-set-up-git
Follow the bit starting at:
Next: Set Up SSH Keys
3. Generate a new SSH key.
1 Comment
I approve. The -m shows up as a little square for some reason though.