Learn how to setup GitHub on your MacBook and upload your first project using Terminal. A step-by-step guide including how to fix the Authentication Failed error in 2026.
So, you've finished your project on your Mac, and now it's time to share it with the world โ or just back it up safely. Moving from local code to a GitHub repository is a rite of passage for every developer.
In this guide, I'll walk you through the exact Terminal commands to get your code live on GitHub, including the fix for the dreaded "Invalid Username or Password" error that trips up almost every beginner.
Let's get into it. how to setup GitHub on MacBook.
What You'll Need Before Starting
- A Mac with Terminal access
- A free GitHub account โ sign up at github.com
- Git installed on your Mac (most Macs have it โ type
git --versionin Terminal to check) - A project folder ready to upload
Step 1: Create Your Repository on GitHub
Before touching your Terminal, you need a place for your code to live online.
- Log in to github.com
- Click the "+" icon in the top-right corner โ select "New repository"
- Give your repository a name (e.g.,
my-flutter-app) - Choose Public or Private
- Do NOT check "Initialize with README" โ we'll push our own files
- Click "Create repository"
- Copy the HTTPS URL shown โ it'll look like:
https://github.com/yourusername/your-repo-name.git
Keep this URL handy โ you'll need it in Step 3.
Step 2: The Mac Terminal Magic
Open your Terminal (Cmd + Space, then type "Terminal"). We're going to Gitify your project folder with these commands in order.
1. Navigate to Your Project Folder
Type cd then drag your project folder from Finder directly into the Terminal window โ it auto-fills the path.
cd /Users/yourname/Documents/YourProjectFolder
2. Initialize Git
This creates a hidden .git folder inside your project that tracks all your changes.
git init
3. Stage Your Files
This tells Git: "Include all these files in my next snapshot."
git add .
The . means "add everything." To add a specific file only, use git add filename.dart.
4. Create Your First Commit
This saves your snapshot locally with a clear, descriptive message.
git commit -m "Initial commit: Flutter project ready"
A good commit message describes what changed โ keep it short and specific.
5. Rename Your Branch to Main
GitHub uses main as the default branch name. This command makes sure your local branch matches.
git branch -M main
Step 3: Connect Your Mac to GitHub
Now we link your local project folder to the remote repository you created in Step 1.
1. Add the Remote Origin
Paste the HTTPS URL you copied from GitHub here:
git remote add origin https://github.com/yourusername/your-repo-name.git
2. The Final Push
Upload your code to GitHub:
git push -u origin main
The -u flag sets origin main as the default, so next time you only need to type git push.
If successful, visit your GitHub repository URL โ your files will be live!
Step 4: Fix the "Authentication Failed" Error (Personal Access Tokens)
If you see this error after running git push:
remote: Support for password authentication was removed. fatal: Authentication failed for 'https://github.com/...'
Don't panic. This is extremely common. GitHub no longer accepts your account password in the Terminal. You need a Personal Access Token (PAT) instead.
How to Generate a Personal Access Token:
- Go to GitHub โ Settings (click your profile photo)
- Scroll down โ click "Developer settings"
- Click "Personal access tokens" โ "Tokens (classic)"
- Click "Generate new token (classic)"
- Add a note like
MacBook Terminal - Set expiration (90 days recommended)
- Under Scopes, check "repo" (full repository access)
- Click "Generate token"
- Copy the token immediately โ GitHub won't show it again!
Use the Token as Your Password:
When Terminal asks for your password during git push, paste your Personal Access Token instead of your GitHub password. That's it โ it'll work instantly.
Pro Tip: To avoid entering the token every time, save it with:
git config --global credential.helper osxkeychain
macOS will store it securely in your Keychain going forward.
Quick Command Cheat Sheet
Here's the full workflow at a glance for your next project:
cd /path/to/your/project git init git add . git commit -m "Initial commit" git branch -M main git remote add origin https://github.com/yourusername/repo.git git push -u origin main
Conclusion
And that's it! Your code is now safely stored on GitHub. By using the Terminal on your Mac, you have full control over your version history and you're one step closer to a professional developer workflow.
GitHub isn't just a backup tool โ it's how the world's best developers collaborate, version, and ship great software. You've just taken your first real step into that world.
Happy Coding! ๐