What is Git? Our beginner’s guide to version control

Let’s get you started on your Git journey with basic concepts to know, plus a step-by-step on how to install and configure the most widely used version control system in the world.

|
| 6 minutes

If you’re new to software development, welcome! We’re so glad you’re here. You probably have a lot of questions and we’re excited to help you navigate them all.

Today, we’re going to dive into the basics of Git: what it is, why it’s important, how you can install and configure it, plus some basic concepts to get you started.

Here’s the deal: Git is the most widely used version control system (VCS) in the world—and version control is a system that tracks changes to files over a period of time.

Let’s use your resume as an example. You’ve probably had several iterations of your resume over the course of your career. On your computer, you probably have separate files labeled resume, resumev2, resumev4, etc. But with version control, you can keep just one main resume file because the version control system (Git) tracks all the changes for you. So, you can have one file where you’re able to see its history, previous versions, and all the changes you’ve made over time.

Git concepts every new dev must know. The defined terms include repository, branching, pulling, pushing, committing, merging, dev environment, and rebasing.

Terms to know

  • Working directory: this is where you make changes to your files. It’s like your workspace, holding the current state of your project that Git hasn’t yet been told to track.
  • Staging area: also called the index, this is where you prepare changes before committing them. It’s like a draft space, allowing you to review and adjust changes before they become part of the project’s history.
  • Local repository: your local repository is your project’s history stored on your computer. It includes all the commits and branches and acts as a personal record of your project’s changes.
  • Remote repository: a remote repository is a version of your project hosted on the internet or network. It allows multiple people to collaborate by pushing to and pulling from this shared resource.
  • Branches: branches are parallel versions of your project. They allow you to work on different features or fixes independently without affecting the main project until you’re ready to merge them back.
  • Pull request: a pull request is a way to propose changes from one branch to another. It’s a request to review, discuss, and possibly merge the changes into the target branch, and is often used in team collaborations.
  • Merge: merging is the process of integrating changes from one branch into another. It combines the histories of both branches, creating a single, unified history.

How do I install Git?

First thing first: to use Git, you’ll need to download it on your machine.

Installing Git on a MacOS

While macOS comes with a preinstalled version of Git, you’ll still want to download it to ensure you have the most up-to-date version.

  1. Get instructions: go to git-scm.com/downloads then click macOS.
  2. Install Homebrew, which will allow you to easily install software on your machine, so let’s copy the command /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)", then open up our terminal, paste the command, and hit enter—this will take a while to run so let’s give it a few moments.
  3. Once Homebrew is installed, return to the download page. Open up your terminal and paste the command brew install git. This will run the installer so we can have Git on our system. When it runs successfully, you now have Git on your machine!
  4. Open up your terminal and run the command git and you should see a list of all the commands available.

Installing Git on Windows 11

If you’re using a Windows machine, click on the Windows icon on the download page. This will give you the most recent version of Git.

Once you have that folder on your machine, double-click it and follow the onscreen wizard prompts:

  1. Click the “Next” button for the following: accept the terms, the location to save Git, and keep the default selections.
  2. Reset the default branch name to “main” as that’s the new convention.
  3. Click the “Next” button to accept the recommended path, the bundled OpenSSH program, and for all the other options.
  4. Click the “install” button.
  5. Once Git is installed on the machine, click the “Finish” button and open your terminal.
  6. Run the command git and you should see a list of all the commands available.

Now, you’re ready to start configuring and using it!

How to configure Git on your machine

Now that you’ve got Git on your machine, it’s time to get it set up. Here’s how to do it.

  1. Open your terminal and type git config --global user.name "FIRST_NAME LAST_NAME" git config --global user.email "MY_NAME@example.com". This tells Git who made a change and will give you credit for the work that was done.
  2. If we run git config you can see all the other configuration options that are available, but we don’t need to worry about that right now.
  3. For now, we can check who Git thinks we are by running git config –list and this will return the configuration options we just set.
  4. Hit Q on your keyboard to exit this screen.

Basic terminal and Git commands

Now that you have a basic config set up, let’s go over some of the most basic terminal and Git commands, so you can start using the tool.

Creating a new folder

  1. Open up your terminal and type mkdir git-practice to create a new folder, then type cd git-practice to go into the folder you just created.
  2. Open the folder in your code editor.

Creating a new file

  1. In your terminal, type touch hello.md to create a new markdown file in our folder.
  2. Navigate to your code editor and you’ll see that file right there—hello.md

Initialize Git or create a new Git repository

  1. Go back to your terminal and run git init in this folder. This is the first command you run in a new project. It allows Git to start tracking your changes.
  2. Run git status and you’ll see that it’s currently tracking the empty hello.md file. This will show your changes and whether they have been staged. It will also show which files are being tracked by Git.

Add changes from the working directory to your staging area

  1. Run git add . Then run git status, and you’ll see a different color of the tracked file hello.md, which indicates that it’s currently in the staging area.
  2. Go back to your code editor and type the following: #I’m learning to use Git!
  3. Save the file and return it to your terminal. When we type git status this will show us that there’s been a change to the hello.md file.

Commit changes

  1. Run git commit -m ‘initial commit’. This command allows you to save your changes with a message attached.

One thing to note is that you’ll be using git status, git add, and git commit very often during your time using Git, so it’s important to practice these commands. You can see a list of all the available commands by running git in your terminal, or you can check out our docs to see a list of commands and how to use them.

Are Git and GitHub the same?

Nope! Git is a version control system that tracks file changes and GitHub is a platform that allows developers to collaborate and store their code in the cloud. Think of it this way: Git is responsible for everything GitHub-related that happens locally on your computer. They both work together to make building, scaling, securing, and storing software easier.

More resources to keep practicing your Git skills:

If you have questions or feedback, pop it in the GitHub Community thread and we’ll be sure to respond!

Written by

Kedasha Kerr

Kedasha Kerr

@ladykerr

I'm a Software Engineer who is passionate about encouraging others to get in the industry. I enjoy community building, content creation and learning deeply about Javascript and Developer Advocacy.

Related posts