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 --versionIf 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 --installIf you prefer the latest standalone version of Git, you can install it using Homebrew:
brew install git2. 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 mainTo verify your configuration:
git config --list3. 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 initCloning 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.git4. 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 statusStage changes: Prepare files for the next commit.
git add filename.txt # Stage a specific file git add . # Stage all changed filesCommit 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-nameSwitch back to the main branch:
git switch mainMerge changes: Combine the branch into your active branch.
git merge feature-nameDelete 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.
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.
Add the key to the macOS Keychain: Create or edit the
~/.ssh/configfile:touch ~/.ssh/config nano ~/.ssh/configAdd the following configuration:
Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_ed25519Save and exit (
Ctrl + O, thenEnter, thenCtrl + X).Add the key to your agent:
ssh-add --apple-use-keychain ~/.ssh/id_ed25519Copy the public key and add it to your Git provider:
pbcopy < ~/.ssh/id_ed25519.pubPaste the copied key into your Git provider's SSH settings.
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.