What's the point of Git?
December 2, 2014, 3:31 pm

Github is not the be all end all of Git. Git without the hub is totally possible, and honestly something that I can't believe isn't being taught to everyone.

So let's get started.

Git without the Hub

Git requires one thing; Git. Git is the language of version control. What is version control? Version control is your way of keeping track of previous states of your various projects. It's like saving, except it's more like snapshots. A snapshot of an entire project. Images, videos, vector files, scripts, documents? All can be controlled by git to be able to roll back to a previous state if necessary.

What's great is you don't need anything other than a terminal to work it. Now if you're on Windows you might be saying "I don't have a terminal". That's right, but you're also on a bad system for development. Windows might be great for graphics, but *NIX systems will always be the place to do dev work. Luckily when you install Git, it will probably give you an application called git-bash. This program will emulate a unix terminal, and all of its commands. So whenever I say open a terminal, I'm telling you Windows users to open up git-bash.

git init

Here's the easy part. Open a terminal. cd to your project directory. Everything you want to track will need to go in one main folder.

~/ $ cd ~/Development/Project/

You might as well ls your files to make sure you're in the right folder.

Project/ $ ls

Great, now that we know how to move around in the terminal, let's go ahead and initialize our folder for git.

Project/ $ git init

If you ls again, you won't notice anything special, but if you ls -a you should now notice a hidden folder showing up called .git. That's where all the magic happens. And when I call it magic, you should know well enough to leave it alone, and allow yourself to be bewildered, because ain't no excuse I can up with to want to dive into that mess of a folder. Suffice to say, thar be magic, and that's where it happens.

git add

So now that we have a sweet .git folder we can actually add some files for tracking. If you're daring, and your project isn't already too very large, you can try out a git status to see how many files are currently untracked. By the way, Git's messages are usually very helpful as to what's going on, so don't just shuffle by them.

Alrighty. Now that you know you have untracked files. Let's add them to the tracking system. You can add each individually, git add file.html, but I actually just got a hernia thinking about that, so an easier way is to just add them all at once.

Project/ $ git add .

That will add every single file recursively into your project as a tracked item. Awesome! If you git status again (do it a lot) you will see that there are now a bunch of green files ready for commitment.

Get over your fear of commitment

Commit often. That's the motto. Commiting with Git is like taking a snapshot of the project. Every time you want to save, go ahead and commit. But hold on there, sparky. Every committal must have a message telling the system, you, and any other team members, why this commitment took place. This step seems unnecessary to first-timers, but trust me, it's your first line defense against the stupidity of you. Be descriptive, and tell yourself the reason for saving at this moment. "I fixed the code". "I added corn chips". "I hate greys".

Project/ $ git commit -m "Initial commit"

The next commitment

After you've added all your files, you don't need to keep adding them. You can just commit with an -a flag. This will update any currently edited files that were previously added to the Git tracker.

Project/ $ git commit -a -m "Updated files"

If however you actually do add any new files, those will need to be specifically added, or inductively added with another git add . command. If you would like to remove files from tracking (perhaps because you deleted them) you can simply git rm file.txt to remove them from tracking.

This was a quick introduction to Git without the Hub. I will do another one of these soon all about stepping back through commits, and also another about branching.