macOS

Git on macOS: Installation and Basic Commands for Beginners

This guide helps beginners master Git on macOS: from installation to first commits. You'll learn to create repositories, add files, and view change history.

Updated at February 16, 2026
10-15 min
Easy
FixPedia Team
Применимо к:Git 2.40+macOS 12+

Introduction / Why This Is Needed

Git is a distributed version control system that tracks changes in files, primarily source code. It allows you to:

  • Revert to any previous version of the project.
  • Work on different tasks in parallel in separate branches.
  • Collaborate with other developers by merging changes.

This guide is your first step. You will install Git, perform basic configuration, and complete your first operations: create a repository, make a commit, and clone a project from GitHub. All of this is done in the macOS terminal.

Requirements / Preparation

Before you begin, ensure you have:

  1. macOS (version 12 Monterey or newer).
  2. Terminal (built into macOS, located in /Applications/Utilities/).
  3. Homebrew (recommended for installing Git). If you don't have it, install it by running in the terminal:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  4. An account on GitHub, GitLab, or another Git hosting service (for the cloning step). You can create this later.

Step 1: Install Git

The simplest way to install Git on macOS is through Homebrew.

  1. Open Terminal.
  2. Update the Homebrew formula list:
    brew update
    
  3. Install Git:
    brew install git
    
  4. Verify the installation by running:
    git --version
    
    The output should look something like: git version 2.42.0.

Alternative: Download the installer from the official Git website and run it, following the instructions.

Step 2: Configure Your Username and Email

Git attaches your name and email to every commit. This is important for tracking who changed what.

  1. In the terminal, run the command with your details:
    git config --global user.name "Your First Last Name"
    
    For example: git config --global user.name "John Doe".
  2. Specify your email (preferably the one linked to your GitHub account):
    git config --global user.email "your.email@example.com"
    
  3. Check your configuration:
    git config --list
    
    In the output, look for the user.name and user.email lines.

Step 3: Create a New Local Repository

Now let's create a project folder and initialize Git in it.

  1. Create a new folder for your project and navigate to it:
    mkdir ~/Projects/my-first-repo
    cd ~/Projects/my-first-repo
    
  2. Initialize an empty Git repository:
    git init
    
    The terminal will respond: Initialized empty Git repository in /Users/your_name/Projects/my-first-repo/.git/.
  3. Create a simple text file (for example, README.md):
    echo "# My First Project" > README.md
    
  4. Add the file to the staging area (index) — this prepares the file for a commit:
    git add README.md
    
    To add all files in the current folder, use git add ..
  5. Create your first commit — a permanent record of changes:
    git commit -m "Added README.md with project description"
    
    The -m flag allows you to specify the commit message directly.

Step 4: Clone an Existing Remote Repository

Often, you start working not with an empty folder, but with an already existing project on GitHub.

  1. Find the desired repository on GitHub (for example, https://github.com/torvalds/linux).
  2. Click the Code button and copy the URL (HTTPS is recommended).
  3. In the terminal, navigate to the folder where you want to place the project:
    cd ~/Projects
    
  4. Run the git clone command with the copied URL:
    git clone https://github.com/torvalds/linux.git
    
    Git will create a linux folder and download the entire project with all its commit history.

Step 5: View the Change History

The git log command helps you see what changed and when.

  1. Navigate to any initialized or cloned repository.
  2. Run:
    git log
    

    You will see a list of commits in reverse chronological order (newest at the top). Each commit shows:
    • commit (a unique hash, e.g., a1b2c3d).
    • Author (the author, from your configuration).
    • Date (date and time).
    • Message (your commit message).

    For a concise output (one line per commit), use git log --oneline.

Step 6: Create and Switch to a New Branch

Branches allow you to isolate the development of new features or fixes from the main codebase (usually the main or master branch).

  1. Ensure you are on the main branch:
    git branch
    
    An asterisk * will indicate the current branch.
  2. Create a new branch named feature-add-login and immediately switch to it:
    git checkout -b feature-add-login
    
    Or in two steps: git branch feature-add-login and git checkout feature-add-login.
  3. Now all new commits will go into this branch, without affecting main. After finishing work, you can merge the branch back into main.

Verification

You have successfully learned the basics if:

  1. The git --version command shows an installed Git version.
  2. git config --list contains your user.name and user.email.
  3. You successfully created a local repository and made a commit (the README.md file appears in the git log history).
  4. You cloned a remote repository and see its files in the folder.
  5. The git branch command shows a list of branches, including the one you created.

Troubleshooting

ProblemPossible CauseSolution
git: command not foundGit is not installed or not added to PATH.Reinstall Git via Homebrew. Ensure the installation completed without errors. Restart Terminal.
fatal: not a git repositoryA Git command (e.g., git commit) is run in a folder that is not a repository.Ensure you are inside the folder where git init or git clone was executed. Use pwd to check the current path.
permission denied error during git cloneNo write permissions in the target directory or an issue with SSH keys.1. Perform the clone in a folder where you have permissions (e.g., ~/Projects).
2. For SSH access, ensure your public key (~/.ssh/id_rsa.pub) is added to your account settings on GitHub.
Don't see changes after git addThe file was not changed or the wrong file was added.Check the repository status: git status. It will show which files are modified, staged for commit (Changes to be committed), or untracked (Untracked files).

F.A.Q.

What's the difference between git init and git clone?
How to fix 'permission denied' error when cloning?
Do I need a GitHub account to use Git?
How to undo the last commit but keep file changes?

Hints

Install Git
Configure username and email
Create a new local repository
Clone an existing remote repository
View change history
Create and switch to a new branch

Did this article help you solve the problem?

FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community