Git for Beginners: Part 1
What is Git? Why Use It? How to install it?
Published: February 25, 2020
- You are here >> git Part 1: What is git? Why Use it? How to install it.
- git Part 2: How to Use git
- git Part 3: Fixing Commits
- git Part 4: Branching
- git Part 5: Resolving Merge Conflicts
- git Part 6: Writing Pull Requests
- git Part 7: Working with a Team
OK, so what is git?
git is 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.
git is a version control system.
All this really means is that it records every change you make to your project files.#
Why use it?
In normal people terms, it means
- You can have unlimited "undos" in your code.
- Imagine being able to go back in time to any point in your project. Maybe that sounds dumb? Why would you want to go back to the very beginning of your project? Well, maybe you could go back to the very beginning of your project to see how you set things up, as 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 chunks of code commented out so you don't "loose" what was previously there. Or, maybe you have multiple veresions of a single file...just in case. — git solves all of 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 on different computers.
- 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, each person will 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 was a fulltime freelancer for 7 years. Even though I worked by myself on most projects, I still used git on every single one of my projects.
git 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 to FTP my files, 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.
git, I make a change to a file. Then, I use a program, called Tower, say, "These are the changes that I made" and it would automatically updates 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 to the other developers in the room to make sure no one else was working on the file we needed to edit. Otherwise, we'd end up overwriting each other and loosing work.
git solves all of that. Furthermore, I can tell who made a change to file and talk to that developer about any specific questions I might have about their code — pretty cool.
Installing git on Your Computer
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.
iTerm2 is pretty great, too.
I prefer these alternatives over the generic Terminal that comes preinstalled on your Mac, because they include a few more options and customizations.
Inside the Terminal, type
git and hit
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 use git, there are a few configurations you'll need to set up:#
$ git config --global user.name "Amy Dutton"
If you want to make sure that it was entered and saved correctly, you can type:
$ git config --global user.name > Amy Dutton
Your email address
$ git config --global user.email "firstname.lastname@example.org"
Same thing, if you want to make sure that it was entered and saved correctly, you can type:
$ git config --global user.email > email@example.com
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:
$ git config user.email "firstname.lastname@example.org"
This means when you make a commit, it will associate the commit with the correct person — And if you're thinking ahead, yes, that means you can tell who made a change to your project, what they did and when.#
You can use git through the Terminal or through a GUI (Graphical User Interface). In my opinion, its 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 is my editor of choice, so its 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. — plus, VS Code is free.#
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 its an app that I use everyday, for me its definitely worth it.#
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.#
I bet you can't guess who created this app. 😏 Yes, GitHub created GitHub Desktop. This is another free app. The only downside is that you can only use this with GitHub. If you're working on a project that uses BitBucket or GitLab, you'll have to use another application.
Sweet! I think you are now set up for success.
Ready to take the next step?
This industry moves fast, but
you can stay up to date:
Receive a weekly email of the internet's best from articles, tutorials, to pro tips.