GitHub: Your Cloud Backup
Last reviewed
BeginnerWhat you'll learn
~25 min- Create a GitHub account and install the GitHub CLI
- Create a remote repository and push a local project to GitHub
- Understand and configure .gitignore to protect secrets and skip generated files
- Set up authentication with gh auth login
- Follow a pre-push checklist before sharing code
You’ll push your first project to GitHub and have a cloud backup you can access from anywhere.
Why This Matters
GitHub is three things at once:
- Your backup. If your laptop dies, your code is safe in the cloud.
- Your portfolio. Employers and collaborators check GitHub profiles. Every project you push is a signal that you build things.
- Your collaboration hub. When you work with others — or even with yourself across multiple machines — GitHub is how code moves between them.
Most professional developers use GitHub or a similar Git hosting platform (GitLab, Bitbucket, Azure DevOps). Setting it up now means every project you build from here forward is automatically backed up and shareable.
The Mental Model: Google Drive for Code
You already use Google Drive or OneDrive to back up documents. GitHub does the same thing for code — but better. Instead of just storing the latest version, GitHub stores the complete history of every change you’ve ever made. You can go back to any point in time, see who changed what, and restore old versions instantly.
| Google Drive | GitHub |
|---|---|
| Upload files to the cloud | Push commits to a remote repo |
| Share a link with collaborators | Share a repo URL |
| See when a file was last modified | See full commit history with messages |
| One version (unless you dig into history) | Full commit history preserved by default |
Prerequisites
Before starting this lesson, make sure you have:
- Git installed and configured (Module 7, Lesson 1) — run
git --versionto verify - A local repository with at least one commit (Module 7, Lessons 2-3) — run
git log --onelineto verify
If either of those fails, go back and complete the earlier lessons first.
Step 1: Create a GitHub Account
If you already have a GitHub account, skip to Step 2.
- Go to github.com/signup (or choose Continue with Google)
- Choose a username — this will be part of your profile URL (
github.com/your-username), so pick something professional - Enter your email and create a password
- Verify your email address when asked
- Your new account is on GitHub Free, which is all you need for this course. You can decide later whether you need a paid plan.
Your GitHub username is visible on every project you share. Use your real name or a professional handle. Avoid joke names — future employers will see this.
Step 2: Let Your Agent Handle the GitHub CLI
The GitHub CLI (gh) lets you create repos and sign in from the terminal. You do not need to install it by hand. Ask your agent:
Check whether the GitHub CLI (
gh) is installed. Install it if needed, help me sign in, and publish this repo to my GitHub account. Ask me before anything is public.
Approve each step as it asks, and finish the browser sign-in when it opens. Then confirm with the agent that gh --version works.
🔍Installing gh by handclick to expand
If you prefer to install it yourself:
- macOS:
brew install gh - Windows (PowerShell):
winget install --id GitHub.cli --source winget - Linux, WSL, Ubuntu, Debian, Fedora: follow GitHub’s official steps at github.com/cli/cli#installation. The
ghin distribution repositories is often too old to work.
Verify with gh --version.
Authenticate with GitHub
Before you can push code, you need to log in:
gh auth loginThis starts an interactive walkthrough. As of gh 2.103 (October 2026), choose these options:
- Where do you use GitHub? →
GitHub.com - How would you like to authenticate GitHub CLI? →
Login with a web browser - What is your preferred protocol for Git operations on this host? →
HTTPS(simpler for beginners; SSH works too) - Authenticate Git with your GitHub credentials? →
Yes
Older versions of gh ask the same questions in a different order.
It will give you a one-time code, open your browser, and ask you to paste it. Once done, you’re authenticated.
🔍HTTPS vs SSHclick to expand
When gh auth login asks about your “preferred protocol,” you are choosing how your computer talks to GitHub:
- HTTPS (recommended for beginners): Uses your browser or a token for authentication. Simpler to set up, works through most firewalls.
- SSH: Uses cryptographic keys stored on your machine. More convenient once set up (no repeated logins), but requires generating and managing key files.
Either works fine. If you are unsure, choose HTTPS. You can switch later.
If your network blocks browser-based auth, choose Paste an authentication token instead. Generate a personal access token (classic) at github.com/settings/tokens with the repo, read:org, and gist scopes (the minimum gh accepts), then paste it when prompted. For SSH key setup, run gh auth login and select the SSH protocol: gh offers to upload your existing SSH key, or to generate and upload a new one if you have none.
Verify that authentication worked:
gh auth statusYou should see your username and the scopes you’ve granted.
.gitignore Essentials
Not everything belongs on GitHub. Some files are generated, some are enormous, and some contain secrets that should never be shared. The .gitignore file tells git which files to skip. Set this up before your first push.
The starter template
Ask your agent to create a .gitignore file for your project, or use this reference starter template in your project root:
REFERENCE FILE .gitignore starter template for web and Python projects open reference hide reference Reference example of a .gitignore file your agent generates to keep secrets, dependencies, and build output out of Git.
# Dependencies (downloaded, not created by you)node_modules/__pycache__/venv/
# Build output (generated, not source code)dist/build/.output/
# Environment variables (secrets!).env.env.local.env.production
# OS files (junk your operating system creates).DS_StoreThumbs.db
# Editor and tool files (personal settings).vscode/.idea/.claude/settings.local.json# (Commit the rest of .claude/: settings.json and skills are shared project config.)
# Logs*.logThe rule of thumb
Commit things you created. Skip things that are generated or downloaded.
| Commit this | Do NOT commit this |
|---|---|
Source code (.js, .html, .css, .py) | node_modules/ (downloaded) |
Configuration (package.json, config files) | .env files (secrets) |
.gitignore itself | Build output (dist/, build/) |
| README and documentation | OS junk (.DS_Store, Thumbs.db) |
| Test files | Large binary files (videos, datasets) |
Which of these files should go in your .gitignore because it holds secrets and must never be committed?
If you pushed a .env file or any file with API keys to GitHub, those secrets are in your git history even if you delete the file. You must:
- Immediately revoke the exposed keys at your API provider’s dashboard and generate new ones
- Remove the file from tracking:
git rm --cached .env - Add
.envto your.gitignore - Commit those changes:
git commit -m "Remove .env from tracking"
For thorough history cleanup, look into git filter-repo — the tool recommended by Git and GitHub for rewriting history to scrub secrets from old commits. But revoking the keys is the urgent first step.
Step 3: Create Your First Remote Repository
If you followed the manual push instructions in Lesson 3, your remote is already set up. Skip to “Future Pushes” below — you just need git push from now on.
Make sure you’re inside your local git project (the one with commits from previous lessons):
Once you push to GitHub, your code is on the internet. Make sure .gitignore is set up first (see above). If you accidentally push secrets like API keys, they are in the git history even if you delete them later. Rotate any exposed keys immediately.
cd ~/my-project # Replace with your project folder (e.g., ~/ai-class, or $HOME\ai-class in PowerShell)git branch -M main # Ensure your branch is named "main" (the modern convention)gh repo create my-first-project --public --source=. --remote=origin --pushGit itself still names a new repository’s first branch master unless you configure it otherwise; Git’s documentation says this will change to main when Git 3.0 is released. This course uses main, so the git branch -M main command renames your current branch to main. If your branch is already called main, the command does nothing harmful.
That single command does everything. Here’s what each flag means:
| Flag | What it does |
|---|---|
my-first-project | The name of your GitHub repo |
--public | Anyone can see it (use --private if you prefer) |
--source=. | Use the current directory as the source |
--remote=origin | Name the remote connection “origin” (the convention) |
--push | Immediately push all your commits to GitHub |
After it runs, you’ll see a URL like https://github.com/your-username/my-first-project. Open it in your browser — your code is on GitHub.
Common issues and fixes:
- “remote origin already exists”: You already have a remote set up. Check it with
git remote -v. Update it withgit remote set-url origin https://github.com/YOUR-USERNAME/REPO.git. - Authentication error: Run
gh auth statusto check if you are logged in. If not, rungh auth loginagain. - Push rejected: Run
git pull --rebase origin mainto sync with the remote, thengit push.
“Origin” is just a nickname for the GitHub URL. When you run git push, git looks up where “origin” points and sends your code there. You can name it anything, but “origin” is the universal convention — every tutorial, every AI tool, and every collaborator expects it.
Back up your project to GitHub
Ask your agent in plain English:
Create a private GitHub repository for this project and push it, then give me the link.
Open the link in your browser to confirm your files are there. The agent picks the right commands for you; you do not need to memorize any flags.
The manual way (without gh CLI)
If you prefer or if gh isn’t available:
- Go to github.com and click + then New repository
- Name it, choose Public or Private, and do not add a README or .gitignore (you already have files)
- Click Create repository
- Copy the commands GitHub shows you and run them:
git remote add origin https://github.com/YOUR-USERNAME/my-first-project.gitgit branch -M maingit push -u origin mainBoth methods get you to the same place. The gh CLI just does it in one step.
Step 4: The Daily Push Workflow
Now that your repo is connected, pushing new work is simple:
git add .git commit -m "Add feature description"git pushThree commands. Your changes are staged, committed, and backed up to GitHub. This is the workflow you’ll use every time you finish a chunk of work.
Push after every meaningful commit — when a feature works, when you fix a bug, when you’re done for the day. Don’t wait until the project is “finished.” Frequent pushes mean frequent backups.
Pre-Push Checklist
Before your first push to GitHub (and as a habit for every new project), verify these items:
.gitignoreis in place and includes generated/downloaded folders (e.g.,node_modules/,venv/,__pycache__/),.env, and build output (dist/)- No API keys or passwords in any committed file — search your code for strings like
sk-(OpenAI and Anthropic keys),AKIA(AWS),ghp_orgithub_pat_(GitHub tokens), orpassword = - The project builds and runs locally — run your project’s start command (
npm run dev,python app.py, or your equivalent) and verify it works - Commits have meaningful messages — not “stuff” or “asdf”
- Project config has a reasonable name —
package.json,pyproject.toml, or equivalent will be public if the repo is public
The checklist takes 30 seconds and prevents embarrassing (or dangerous) mistakes. Treat it like a pilot’s pre-flight check — boring but critical.
🧬In Your Field: Biotechclick to expand
Research data and lab notebooks. GitHub repositories make excellent homes for research tool code, analysis scripts, and computational protocols. Keep your raw data in separate storage (institutional servers, cloud storage) and use git for the code that processes that data. Your commit history becomes a traceable record of how your analysis evolved — “Add normalization step for RNA-seq counts,” “Fix batch effect correction,” “Update p-value threshold to 0.01.” When you publish, you can link to the exact commit used for the results in your paper. Some journals now require this level of reproducibility.
📊In Your Field: MIS / Businessclick to expand
Private repos for business projects. When building dashboards, automation scripts, or report generators for a business context, use --private instead of --public when creating repos. Private repositories are free on GitHub and ensure that proprietary business logic, client data schemas, and internal tool configurations stay confidential. You can always change a repo from private to public later — but you can’t un-publish something once it’s been public. When in doubt, start private.
🏛️In Your Field: Government Devclick to expand
GitHub Enterprise and restricted environments. Many government agencies use GitHub Enterprise, GitLab, or Azure DevOps instead of public GitHub. The git commands are identical; the only difference is the URL in git remote add origin. Check with your IT team about which hosting service is approved. Some agencies require security scanning (like GitHub Secret Protection and GitHub Code Security, the products formerly sold together as GitHub Advanced Security, or Snyk) before code can be pushed. If your network restricts access to github.com, ask about VPN exceptions for developer tools or use your agency’s internal Git hosting. The key point: get your work off your local machine and into a backed-up, access-controlled repository.
When Things Go Wrong
Use the Symptom → Evidence → Request pattern: describe what you see, paste the error, then ask for a fix.
Key Takeaways
- GitHub is your cloud backup and portfolio. Every project you push is safe from hardware failure and visible to collaborators (or employers).
- Push after every meaningful change. Don’t wait until the project is “done.” Frequent pushes mean frequent backups.
.gitignoreprotects your secrets. Always set it up before your first commit. Never push.envfiles,node_modules/, or build output.- The
ghCLI simplifies everything. One command to create a repo and push — no browser required. - The daily rhythm is simple:
git add .,git commit -m "message",git push. Three commands, ten seconds, complete backup.
What does a .gitignore file do?
You just created a new project and want to back it up to GitHub. What's the correct order of steps?