Git is the tool that tracks changes to your code over time. GitHub is a website that stores a copy of that history online, so you can back it up, share it, and work on it from more than one computer. This guide covers getting both connected on a Mac.
If you've completed Step 1 of the main guide (Xcode Command Line Tools), you already have Git installed, it comes bundled in.
Verify it worked:
git --versionWhat this does: prints the installed Git version. If you see a version number, you're set and can skip to the next section. If you see a popup asking to install developer tools instead, click Install, wait a few minutes, then run this command again.
Go to github.com/join and sign up. It's free for personal use. Pick a username, you'll see it in URLs and it's what others will use to find you, so something professional is worth it if you'll use this for work.
The GitHub CLI (gh) is a tool that handles logging in and talking to GitHub from the terminal, so you don't have to manually set up separate keys or passwords.
brew install ghWhat this does: downloads and installs the GitHub CLI using Homebrew.
Verify it worked:
gh --versionWhat this does: prints the installed version.
gh auth loginWhat this does: starts an interactive setup. Answer the prompts like this:
- What account do you want to log into? →
GitHub.com - What is your preferred protocol for Git operations? →
HTTPS - Authenticate Git with your GitHub credentials? →
Yes - How would you like to authenticate? →
Login with a web browser
It'll show you a one-time code and open your browser. Paste the code in, approve, and you're done, gh and Git are both now authenticated.
Note
There's an older, more manual way to do this involving SSH keys (a pair of cryptographic files that prove it's you, without a password). gh auth login skips all of that for you. If a tool or tutorial specifically asks for an SSH key later, you can generate one then, it's not needed to get started.
GitHub needs to know a name and email to attach to your commits (a commit is a saved snapshot of changes, labeled with who made it and why).
git config --global user.name "Your Name"
git config --global user.email "your@email.com"What this does: saves your name and email in Git's global settings, so every commit on this Mac, in every project, is automatically labeled with them. Use the same email your GitHub account uses, so GitHub can match your commits to your profile.
"Cloning" means downloading a full copy of a GitHub repository (a project's folder of files plus its whole history) onto your Mac.
gh repo clone owner/repo-nameWhat this does: downloads the repository into a new folder named after it, in whatever folder you ran the command from. Replace owner/repo-name with a real one, for example gh repo clone ngreenwall/dev-environment-starter-kit.
Inside a repo folder, after you've changed or added a file:
git add .
git commit -m "Describe what you changed"
git pushWhat this does:
git add .stages every changed file (marks it as ready to be included in the next commit)git commit -m "..."saves a snapshot of the staged changes with a short message describing themgit pushuploads that snapshot to GitHub
- GitHub CLI:
brew uninstall gh - Git login:
gh auth logout - Git identity: re-run the Step 4 commands with new values to overwrite them