How to Manage Git Repositories on macOS 13

This guide provides a comprehensive overview of managing Git version control repositories on macOS 13 (Ventura). You will learn how to verify and install Git, configure your environment, initialize local projects, handle daily version control workflows, set up SSH keys for remote hosting platforms like GitHub or GitLab, and leverage graphical user interface options.

1. Verify or Install Git

macOS 13 includes Git through Apple's Command Line Tools. To verify if it is installed or to trigger the installation, open the Terminal application (found in Applications > Utilities) and run:

git --version

If Git is not installed, a prompt will appear asking to install the Xcode Command Line Tools. Click Install and follow the prompts. Alternatively, you can force the installation prompt by typing:

xcode-select --install

If you prefer the latest standalone version of Git, you can install it using Homebrew:

brew install git

2. Configure Global Git Settings

Before creating or editing repositories, establish your identity so your commits are properly attributed.

git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
git config --global init.defaultBranch main

To verify your configuration:

git config --list

3. Initialize or Clone a Repository

Initializing a New Local Repository

Navigate to the directory where your project lives and initialize Git:

cd /path/to/your/project
git init

Cloning an Existing Remote Repository

To copy an existing project from a remote host to your Mac:

cd /path/to/target/directory
git clone https://github.com/username/repository.git

4. Daily Version Control Commands

Once a repository is set up, use standard Git commands within your project folder to manage your code history:

  • Check status: See modified, staged, or untracked files.

    git status
  • Stage changes: Prepare files for the next commit.

    git add filename.txt     # Stage a specific file
    git add .                # Stage all changed files
  • Commit changes: Save staged changes to history.

    git commit -m "Describe your changes clearly"
  • View history: Inspect the commit log.

    git log --oneline

5. Managing Branches

Branching allows you to develop features or fixes without disrupting the main codebase.

  • Create and switch to a new branch:

    git switch -c feature-name
  • Switch back to the main branch:

    git switch main
  • Merge changes: Combine the branch into your active branch.

    git merge feature-name
  • Delete a branch:

    git branch -d feature-name

6. Working with Remotes and SSH Keys

To sync code with platforms like GitHub, GitLab, or Bitbucket, configure an SSH key to authenticate securely on macOS 13.

  1. Generate an SSH key:

    ssh-keygen -t ed25519 -C "youremail@example.com"

    Press Enter to accept the default file location, then optionally provide a passphrase.

  2. Add the key to the macOS Keychain: Create or edit the ~/.ssh/config file:

    touch ~/.ssh/config
    nano ~/.ssh/config

    Add the following configuration:

    Host *
      AddKeysToAgent yes
      UseKeychain yes
      IdentityFile ~/.ssh/id_ed25519

    Save and exit (Ctrl + O, then Enter, then Ctrl + X).

  3. Add the key to your agent:

    ssh-add --apple-use-keychain ~/.ssh/id_ed25519
  4. Copy the public key and add it to your Git provider:

    pbcopy < ~/.ssh/id_ed25519.pub

    Paste the copied key into your Git provider's SSH settings.

  5. Push and Pull Changes:

    git push origin main
    git pull origin main

7. Optional GUI Clients for macOS 13

While Terminal provides complete control, several native and cross-platform GUI clients simplify visual branch management on macOS Ventura:

  • GitHub Desktop: Clean, simple interface for GitHub-centric workflows.
  • Sourcetree: Feature-rich client supporting complex branching workflows.
  • Visual Studio Code: Includes built-in source control tools and diff viewers for developers writing code inside the editor.