Git

Git

What is git? Why use it? How to install it.

git for Beginners


Published: February 25, 2020

Today, we're going to be talking about What is git?! Maybe you've heard of it, maybe you haven't. Maybe you've seen GitHub.com and wondered exactly what it does or who its for. — Well, today, let's talk about it!

OK, so what is git?

git is a version control system.

It's not tied to any particular type of project, technology, or framework. You can use it if you're building iPhone apps, websites, or writing documents — it's really quite flexible.

All this really means is that it records every change you make to your project files.

Why use it?

Maybe that means something to you, maybe it doesn't. In normal people terms, it means

  1. You can have unlimited "undo"s in your code.
    • Imagine being able to go back in time to any point in your project. Maybe that sounds dumb to you? Why would you want to go back to the very beginning of your project? What would you do with that? You're right, that would be dumb...but, you could go back to the very beginning of your project to see how you set things up, as a reference for another project. Now, that's valuable!
    • Or, maybe a more likely scenario: you're experimenting with something in your code and you have all these chunks for code commented out or so you don't "lose" what was previously there. Or maybe you have multiples of a single file...just in case. — git solves all of that.
  2. It also means that you can work with a team of people without ever overwriting each other’s code. In fact, you can both be working on the same file at the same time.
  3. An added perk is file backup. You'll have a copy of the code on your computer, another copy online, and if you're working with other people, they'll all have a copy on their machine, as well.

Real-World Examples

Still not convinced? Let me give you a couple of real-world examples.

Freelancing / Working Solo

I did freelancing on my own for 7 years. I still used git on every single one of my projects, even though I didn't collaborate with other developers very often.

It provided a better workflow and it saved my butt a couple of times.

Let me show you the old way...

I would fire up Transmit, find the files that I had updated and drag and drop them over. — every time a change was made. I'd have to remember what files I had changed and sometimes go into multiple directories to find the changed files. — doable, but definitely a pain.

With git, I make a change to a file. Then, I actually use a program called Tower and say, "These are the changes that I made" and it would automatically update my server for me! We can get more into that workflow later, but that might whet your appetite.

Working with a Team

When working with a team, git is even more awesome.

I've been building websites for almost 20 years. Right out of college, I worked at an agency. We would have to talk back and forth (ugh 😜) to make sure that the person sitting next to us didn't have the file we needed open. Otherwise, we'd end up overwriting each other and losing the work.

Again, git solves all of that. Furthermore, I can tell who made a change to file and talk to them about any questions I might have about their code — pretty cool.

Installing git on Your Computer

To install git on a Mac, it's pretty easy. Just open up your Terminal. — You can do this by going to Applications/Utilities or typing Terminal into Spotlight.

If you want to be fancy like me, I'm using Hyper with Cobalt2.

iTerm2 is pretty great too.

I'll include links in the description below.

These alternates just include a few more options and customizations than the generic Terminal that comes installed on your Mac.

Moving on...

Once you get your Terminal open, type git and hit ENTER

If you don't have git installed already, a dialog will appear that says "The git command requires the command line developer tools. Would you like to install the tools now?"

Click Install and "Agree to the Terms of Service" when it comes up.

When it's finished, you can click Done.

The first time you're setting up git, there are a few configurations you'll need to set up:

Your name

1 git config --global user.name "Amy Dutton"

If you want to make sure that it was entered and saved correctly, you can type

1 2 git config --global user.name > Amy Dutton

Your email address

1 git config --global user.email "amy@selfteach.me"

Same thing, if you want to make sure that it was entered and saved correctly, you can type

1 2 git config --global user.email > amy@selfteach.me

As a quick side note. If you want to set up the email address for a specific project, you'll use the same commands, except leave off the --global flag. So, it will just look like this:

1 git config user.email "hello@selfteach.me"

This just means when you make a commit, it will associate the commit with the correct person — And if you're thinking ahead, that means that you can tell who made a change to your project, what they did exactly, and when.

Tooling

You can use git through the Terminal, or a GUI (Graphical User Interface). In my opinion, it's helpful to learn the vocabulary and the theory first, then, those concepts will transfer no matter what tech you use.

I'll include links to all of these within the description below.

VS Code

VS Code is my editor of choice, so it's pretty cool that they have an entire section of their app dedicated specifically to git. You don't even have to leave the code you're working on, you can do everything right there. — and VS Code is free.

git insid VS Code

Tower

Tower is my weapon of choice. I've been using it for years. When I started, there weren't as many options, or at least, not as many options that actually worked and looked good. Within the last couple of years, they've changed their pricing model, so you do have to pay for it every year, but it's an app that I use every day, for me, it's definitely worth it.

git inside Tower

SourceTree

There are a few people that I work with that use SourceTree. It's made by the same people that make BitBucket, Jira, and Trello — if you've heard of those applications. It's free, which is a huge win. I don't have a ton of experience with it though, so I can't speak to the user interface.

Sourcetree

GitHub Desktop

I bet you can't guess who created this app. smirk. Yes, GitHub created GitHub Desktop. This is another free app. The only downside is that you can only use it with GitHub. So, if you're working on a project that has code at BitBucket or GitLab, you'll have to use another application.

GitHub Desktop

Git Fork and GitKraken

Then, just for good measure, Git Fork and GitKraken are 2 other options... But, in full disclosure, I haven't used them before.

Sweet! I think you are now set up for success.

Horizontal Divider

Comments

This industry moves fast, but you can stay up to date:

Receive a weekly email of the Internet's best from articles, to tutorials, to pro tips.