Skip to main content
Back to Blogs
JavaGitDeveloper ToolsSetupApril 2, 2025

Git Setup on Mac

If Homebrew isn’t installed on your Mac yet. Let’s get that installed first. To Install Homebrew on macOS: Open Terminal,

If Homebrew isn’t installed on your Mac yet. Let’s get that installed first.


To Install Homebrew on macOS:

Open Terminal, then copy-paste the following and press Enter

/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”

After it’s installed:

1. Add Homebrew to your shell profile

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

2. Now verify installation:

brew --version

3. Then try:

brew install wget

Set Up Git (First Time Only)

Open a terminal and set your name and email:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

You can verify with:

git config --list

Authenticate GitHub

If using SSH:

  1. Generate SSH key (if you don’t have one): ssh-keygen -t ed25519 -C "you@example.com"
  2. Add the SSH key to your GitHub account:
    GitHub SSH Key Setup Guide

Or use HTTPS:

You’ll authenticate with GitHub username + personal access token (instead of password).

Clone and Check Out the master Branch (if it exists)

mkdir gitrepo
cd gitrepo
git clone --branch master --single-branch https://github.com/username/repo-name.git

  • --branch master: checks out the master branch directly
  • --single-branch: avoids downloading other branches

Here’s a quick and complete checklist to push your files to GitHub — whether it’s a new repo or an existing one:

If You’re Pushing a New Project to GitHub:

cd /path/to/your/project

1. Initialize Git (if not already done)

git init

2. Add all files

git add .

3. Commit your changes

git commit -m “Initial commit”

4. Add remote (replace with your repo link)

git remote add origin https://github.com/your-username/your-repo.git

5. Push to GitHub (assumes branch is main or master)

git push -u origin main # or ‘master’ depending on your setup

If You Cloned a Repo and Just Want to Push Changes

cd repo-folder
git add .
git commit -m “Your commit message”
git push # uses the tracked branch (like main or master)

If You’re Not Sure Which Branch You’re On:

git branch # shows current branch
git status # shows changes and branch

To get the latest changes that were pushed to GitHub by another user, you’ll pull those changes into your local repository.

git pull origin main (# or master, depending on your branch name)

Optional: If You Want to Just Fetch First (Preview Changes)

git fetch origin
git log HEAD..origin/main –oneline # shows new commits not yet merged
git merge origin/main # merges them manually if desired