What Git is and why it matters

Git is the most widely used version control system (VCS) in the world. A version control system tracks changes to files over time. Instead of maintaining multiple files like resume, resumev2, and resumev4, Git lets you keep one file while preserving its full history—every previous version and every change you've made.

Git is not the same as GitHub. Git is the version control tool that runs locally on your computer, while GitHub is a cloud platform for storing code and collaborating with others. They work together to support building, scaling, and securing software.

Core concepts

Before running commands, it helps to understand the areas Git moves your work through:

  • Working directory: where you make changes to files. This is the current state of your project that Git hasn't been told to track yet.
  • Staging area: also called the index, this is where you prepare changes before committing them. It's a draft space for reviewing and adjusting before the changes enter project history.
  • Local repository: your project's history stored on your computer, including all commits and branches.
  • Remote repository: a version of your project hosted on the internet or network, enabling collaboration through pushes and pulls.
  • Branches: parallel versions of your project for working on features or fixes independently, without affecting the main project until you merge them back.
  • Pull request: a proposal to merge changes from one branch into another, often used for review and discussion in team collaboration.
  • Merge: the process of integrating changes from one branch into another, combining their histories into one.

Installing Git

On macOS

macOS ships with a preinstalled Git version, but you'll still want to download the latest from git-scm.com/downloads to stay current.

  1. Go to git-scm.com/downloads and click macOS.
  2. Install Homebrew by copying the command /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)", pasting it into your terminal, and pressing enter. This will take a few moments to run.
  3. Once Homebrew is installed, run brew install git in your terminal. This installs Git on your system.
  4. Run the command git in your terminal—you should see a list of all available commands.

On Windows 11

Click the Windows icon on the download page for the most recent Git version. Once the installer folder is on your machine, double-click it and follow the wizard:

  1. Click "Next" to accept the terms, choose the location, and keep the default selections.
  2. Set the default branch name to "main," as that's the current convention.
  3. Click "Next" to accept the recommended path, the bundled OpenSSH program, and all other options.
  4. Click "Install," then click "Finish" and open your terminal.
  5. Run the command git—you should see a list of all available commands.

Configuring Git

After installation, set your identity so Git knows who made changes:

  1. In your terminal, run git config --global user.name "FIRST_NAME LAST_NAME" and git config --global user.email "[email protected]". This gives you credit for your work.
  2. Run git config to see other available configuration options—these aren't needed right now.
  3. Check who Git thinks you are with git config --list, which returns the options you just set.
  4. Press Q to exit the screen.

First commands: setup and basic workflow

Once configured, create a practice project and move some files through Git's workflow:

Create a folder and file

  1. Run mkdir git-practice to create a new folder, then cd git-practice to move into it.
  2. Open the folder in your code editor.
  3. Run touch hello.md to create a Markdown file in the folder.
  4. You'll see the hello.md file in your code editor.

Initialize a repository

  1. Run git init in the folder. This is the first command for a new project—it lets Git start tracking your changes.
  2. Run git status and you'll see Git is tracking the empty hello.md. This command shows your changes, whether they're staged, and which files Git tracks.

Stage changes

  1. Run git add . followed by git status. The tracked hello.md file will appear in a different color, indicating it's staged.
  2. In your code editor, type: #I'm learning to use Git!
  3. Save the file and run git status in your terminal—it will show that a change has been made to hello.md.

Commit changes

  1. Run git commit -m 'initial commit' to save your changes with an attached message.

You'll use git status, git add, and git commit constantly while working with Git. Run git in your terminal for a full list of commands, or see GitHub's command reference for usage details.

Practice resources

To build your skills further, explore these resources: