0

Welcome to Git & GitHub Training

What you'll learn

This training will take you from zero to confidently using Git and GitHub. By the end, you'll be able to:

  • Set up a GitHub account and connect it to your machine
  • Clone repositories (download code from GitHub)
  • Make changes and push them to GitHub
  • Pull updates from teammates
  • Understand branches and how to avoid conflicts
  • Keep passwords and secrets out of GitHub

Who is this for?

Complete beginners. No prior Git experience needed. If you've never used a terminal before, that's fine too — we'll walk through everything step by step.

Works on Windows AND Mac

All commands in this training work on both Windows and Mac. We'll use the VS Code terminal — the same editor you probably already have. No need to open a separate app.

Where to type commands: Open VS Code, then press Ctrl+` (backtick) on Windows or Cmd+` on Mac to open the built-in terminal. That's where all the commands in this training go.

How long does this take?

About 30-45 minutes to read through. You can follow along on your own machine as you go, or read first and try later.

1

What is Git?

The "Save Game" Analogy

Think of Git like save points in a video game. Every time you "commit," you're creating a save point. You can:

  • See the history of every save you've ever made
  • Go back to any previous save if something breaks
  • Work on different things without messing up your main save

Git vs GitHub

Git

The tool on your computer that tracks changes to files. It's like a super-powered "Track Changes" — but for code.

Runs locally on your machine

GitHub

A website that stores your Git history in the cloud. Think of it as OneDrive/SharePoint, but designed specifically for code.

Lives on the internet

Why use Git instead of just sharing files on OneDrive?

Feature OneDrive / Email Git + GitHub
Version history Limited, hard to find Every change logged with a message
Who changed what? Hard to tell Every change tagged with author
Two people edit the same file One person's changes get overwritten Git merges both or warns you
Undo a mistake Hope you have a backup... Revert to any previous version
Passwords in code Easy to accidentally share .gitignore blocks sensitive files

Key Takeaway

Git does NOT auto-save. You decide when to save (commit) and when to upload (push). Nothing goes to GitHub unless you explicitly tell it to.

2

Account Setup

Step 1: Get a GitHub account

If you don't have one yet, ask your team lead or IT admin to add you to the MercuryInsuranceEI GitHub organization. You'll receive an invite email.

If you need to create an account first:

  1. Go to github.com and click "Sign up"
  2. Use your work email
  3. Choose a username (e.g., yourname_MIG)
  4. Accept the organization invite when you receive it

Step 2: Authenticate with GitHub CLI

Open your terminal (Terminal on Mac, or the VS Code terminal) and run:

Terminal
gh auth login

When prompted, choose:

1
What account?

GitHub.com

2
Preferred protocol?

HTTPS

3
Authenticate Git with GitHub credentials?

Yes

4
How to authenticate?

Login with a web browser (it will give you a code to paste)

Step 3: Set your identity

Tell Git who you are (this tags your commits with your name):

Terminal
git config --global user.name "Your Name"
git config --global user.email "yourusername@mercuryinsurance.com"
One-time setup! You only need to do Steps 2 and 3 once. After that, your machine remembers.

Step 4: Verify it worked

Terminal
gh auth status

You should see something like:

github.com
  ✓ Logged in to github.com account yourname_MIG
  - Active account: true
  - Git operations protocol: https
3

Install Tools

You need all 3 of these tools

Each one does something different — they work together:

Tool Why you need it Required?
VS Code Your code editor. It has a built-in terminal (where you type Git commands) and a visual Git panel. This is where you'll do all your work. Yes
Git The actual version control engine. This is what tracks changes, creates commits, and syncs with GitHub. VS Code uses Git behind the scenes — it won't work without it. Yes
GitHub CLI (gh) Makes logging into GitHub painless — one command instead of setting up SSH keys or tokens manually. Also makes cloning repos easier. Recommended
Think of it this way: VS Code is where you write code, Git is what saves and tracks your changes, and GitHub CLI is the easy login helper. You need VS Code + Git at minimum. GitHub CLI just makes the setup much smoother.

Open the VS Code Terminal

All commands in this training are run inside VS Code's built-in terminal. To open it:

Windows

Press Ctrl + ` (backtick, the key above Tab)

The terminal opens at the bottom of VS Code

Mac

Press Cmd + ` (backtick)

The terminal opens at the bottom of VS Code

Windows users — which shell? VS Code defaults to PowerShell, which works great. All git and gh commands work the same in PowerShell, Command Prompt (cmd), and Git Bash. The winget install commands below need PowerShell or CMD. You can switch your default shell in VS Code: click the dropdown arrow next to the + in the terminal panel.

Install Git

First, check if it's already installed:

VS Code Terminal (any OS)
git --version

If you see a version number, you're good! If not:

Windows

Download and run the installer from git-scm.com

Use all the default options during install. Restart VS Code after.

Or if you have winget:

winget install Git.Git

Mac

Usually pre-installed. If not:

brew install git

Don't have Homebrew? Install it from brew.sh first.

Install GitHub CLI (gh)

Check if installed:

VS Code Terminal
gh --version

If not installed:

Windows

winget install GitHub.cli

Restart VS Code after installing.

Mac

brew install gh
All git commands are the same on Windows and Mac. Once Git and gh are installed, every command in this training (git add, git commit, git push, etc.) works identically on both platforms. No need to memorize different commands.
4

Clone a Repo

What is cloning?

Cloning = downloading a copy of a project from GitHub to your machine.

It's like copying a shared folder from OneDrive to your Desktop — except Git remembers where it came from and can sync changes both ways.

How to clone

Terminal
gh repo clone MercuryInsuranceEI/RepoName

Or using the full URL:

Terminal
git clone https://github.com/MercuryInsuranceEI/RepoName.git

This creates a folder called RepoName in your current directory with all the project files.

What you'll see:

Cloning into 'RepoName'...
remote: Enumerating objects: 47, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (32/32), done.
Receiving objects: 100% (47/47), 15.2 KiB | 7.60 MiB/s, done.
Resolving deltas: 100% (12/12), done.

After cloning

Terminal
# Move into the project folder
cd RepoName

# See what files are there
dir          # Windows (CMD or PowerShell)
ls           # Mac / Linux / Git Bash

# Open it in VS Code
code .
Where should I clone? Clone to your home directory or a projects folder — NOT inside OneDrive. Git and OneDrive don't play well together (OneDrive tries to sync the .git folder and causes corruption).
5

The Basic Workflow

The 4-Step Loop

This is 90% of everything you'll ever do in Git:

1
Edit
Change your files normally
2
Add
git add
3
Commit
git commit
4
Push
git push

What each step does

Step Command What it does Analogy
1. Edit (just edit files normally) Make changes to your code Writing on paper
2. Add git add filename Stage files — tell Git which changes to save Putting papers in an envelope
3. Commit git commit -m "message" Save a snapshot with a description Sealing the envelope with a label
4. Push git push Upload to GitHub Mailing the envelope

Checking what's going on

At any time, you can see the current state of your project:

Terminal
git status

This shows you:

  • Red files = changed but not staged (not in the envelope yet)
  • Green files = staged and ready to commit (in the envelope)
  • Nothing = everything is clean, nothing to do
6

Making Changes

Full walkthrough: editing a file and pushing it

Let's say you edited server.js to fix a timeout issue. Here's exactly what you'd type and see:

Step 1: Check what changed

You type:
git status
You see:
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)

        modified:   server.js

no changes added to commit (use "git add" to stage)

The file shows in red — it's changed but not staged yet.

Step 2: Stage the file

You type:
git add server.js
git status
You see:
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)

        modified:   server.js

Now it's green — staged and ready to commit.

Step 3: Commit with a message

You type:
git commit -m "Fix timeout issue in API call"
You see:
[main a1b2c3d] Fix timeout issue in API call
 1 file changed, 3 insertions(+), 1 deletion(-)

Step 4: Push to GitHub

You type:
git push
You see:
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 312 bytes | 312.00 KiB/s, done.
To https://github.com/MercuryInsuranceEI/RepoName.git
   f4e5d6c..a1b2c3d  main -> main

Done! Your changes are now on GitHub.

Adding multiple files

Terminal
# Add specific files
git add server.js public/styles.css

# Or add ALL changed files (be careful with this)
git add .
Be careful with git add . — this adds EVERYTHING. If you accidentally have a .env file or credentials in the folder, they could get committed. Prefer adding specific files by name.

Writing good commit messages

Bad Messages

  • "update"
  • "fix"
  • "stuff"
  • "asdfghjkl"

Good Messages

  • "Fix login timeout on slow connections"
  • "Add email notification for failed reports"
  • "Update VIP list with new executives"
  • "Remove deprecated API endpoint"

Rule of thumb: Describe what you changed and why, not how. Future you (or a coworker) should understand the change from just the message.

Adding a new file to the repo

New files work the same way — Git notices them as "untracked":

Terminal
# Create or copy a new file into your project folder
cp ~/Desktop/new_script.py .

# Git status shows it as "Untracked"
git status

# Add, commit, push — same as before
git add new_script.py
git commit -m "Add new automation script for weekly data pull"
git push
7

Pulling Updates

When someone else makes changes

If a coworker pushes changes to GitHub, you need to pull them to get their updates:

Terminal
git pull

What you'll see:

If there are new changes:
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
Unpacking objects: 100% (3/3), 298 bytes | 298.00 KiB/s, done.
From https://github.com/MercuryInsuranceEI/RepoName
   a1b2c3d..e7f8g9h  main     -> origin/main
Updating a1b2c3d..e7f8g9h
Fast-forward
 server.js | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
If you're already up to date:
Already up to date.

That's it! Git downloads their changes and merges them with your local copy.

Good habit: Pull before you push

Always git pull before you start working, and again before you git push. This prevents conflicts.

Daily routine
# Start of day
git pull

# ... do your work ...

# Ready to push
git pull          # Get any changes first
git add .
git commit -m "Your changes"
git push

What if pull fails?

If you get a message about conflicts, don't panic! Jump to the Merge Conflicts section.

8

Branches

What are branches?

A branch is like a parallel universe for your code. You can make changes in a branch without affecting the main version. When you're happy with your changes, you merge them back.

main
1 2 3 6
your-feature
4 5

When to use branches

  • Small solo projects: You can work directly on main — branches are optional
  • Team projects: Use branches to avoid stepping on each other's toes
  • Big changes: Use a branch so you can experiment without breaking the main code

Branch commands

Terminal
# Create a new branch and switch to it
git checkout -b my-new-feature

# See all branches (* = current)
git branch

# Switch between branches
git checkout main
git checkout my-new-feature

# Push a branch to GitHub
git push -u origin my-new-feature

# When done, merge back to main
git checkout main
git pull
git merge my-new-feature
git push
Pro tip: For small teams just starting with Git, it's totally fine to all work on main. Branches are a more advanced workflow — learn the basics first, add branches later when you're comfortable.

Bonus: git stash (save work for later)

Sometimes you're in the middle of changes and need to switch branches, but you're not ready to commit yet. git stash saves your work-in-progress temporarily:

Terminal
# Save your uncommitted changes
git stash

# Switch to another branch, do whatever you need...
git checkout main
git pull

# Come back and restore your saved changes
git checkout my-feature
git stash pop

git stash = tuck your work in a drawer. git stash pop = take it back out. Your changes reappear exactly as you left them.

9

Pull Requests

What is a Pull Request?

A Pull Request (PR) is how teams review and approve changes before they go into the main code. Instead of pushing directly to main, you:

  1. Create a branch and make your changes
  2. Push the branch to GitHub
  3. Open a Pull Request — "Hey team, I made these changes, can someone review?"
  4. A teammate reviews and approves (or requests changes)
  5. Once approved, merge the PR into main

Why use Pull Requests?

  • Code review — Someone else checks your work before it goes live
  • Discussion — Teammates can comment on specific lines and suggest improvements
  • Safety — Prevents untested code from going directly into main
  • History — PRs create a record of why changes were made and who approved them

Creating a Pull Request (step by step)

Step 1: Create a branch and make your changes:

Terminal
# Create a branch
git checkout -b fix-login-timeout

# Make your changes, then commit
git add server.js
git commit -m "Fix login timeout on slow connections"

Step 2: Push your branch to GitHub:

Terminal
git push -u origin fix-login-timeout
You see:
remote: Create a pull request for 'fix-login-timeout' on GitHub by visiting:
remote:   https://github.com/MercuryInsuranceEI/RepoName/pull/new/fix-login-timeout
To https://github.com/MercuryInsuranceEI/RepoName.git
 * [new branch]      fix-login-timeout -> fix-login-timeout

Step 3: Open the PR on GitHub — click the link in the output, or go to your repo on github.com and click the yellow "Compare & pull request" banner that appears.

Step 4: Fill in the PR details:

  • Title: Short description (e.g., "Fix login timeout on slow connections")
  • Description: What you changed, why, and anything reviewers should know
  • Click "Create pull request"

Reviewing a Pull Request

When a teammate opens a PR, you'll see it on your repo's Pull requests tab on GitHub. To review:

  1. Click the PR to open it
  2. Go to the Files changed tab to see what was modified
  3. Click on any line to leave a comment
  4. Click "Review changes" at the top and choose:
    • Approve — looks good, merge it
    • Request changes — something needs fixing first
    • Comment — just a note, no approval/rejection

Merging a Pull Request

Once approved, click the green "Merge pull request" button on GitHub. Then clean up:

Terminal (after merging on GitHub)
# Switch back to main and get the merged changes
git checkout main
git pull

# Delete the old branch (optional but keeps things tidy)
git branch -d fix-login-timeout
When to use PRs vs. pushing to main directly: For solo projects or small quick fixes, pushing to main is fine. For team projects or significant changes, always use a PR. When in doubt, use a PR — it's good practice.
10

Merge Conflicts

What is a merge conflict?

A conflict happens when two people edit the same line of the same file. Git doesn't know which version to keep, so it asks you to choose.

Don't panic! Conflicts are normal and easy to fix. They're not errors — they're Git asking for your help.

What a conflict looks like

Git marks the conflicting section in the file:

server.js (conflicted)
<<<<<<< HEAD
const timeout = 5000;    // Your version
=======
const timeout = 10000;   // Their version
>>>>>>> main

How to fix it

  1. Open the file in VS Code (it highlights conflicts for you)
  2. Choose which version to keep (or combine both)
  3. Delete the conflict markers (<<<<<<<, =======, >>>>>>>)
  4. Save the file
  5. Stage and commit the fix:
Terminal
git add server.js
git commit -m "Resolve merge conflict in timeout value"
git push

How to avoid conflicts

  • Pull often — run git pull before starting work
  • Push often — don't sit on changes for days
  • Communicate — let your team know if you're working on the same file
  • Work on different files when possible
11

.gitignore & Project Files

NEVER commit passwords or API keys

This is the #1 rule of Git. If a password ends up on GitHub, consider it compromised — even in a private repo.

What is .gitignore?

A .gitignore file tells Git which files to completely ignore. These files will never be tracked, staged, or pushed — even if you run git add .

Example .gitignore

.gitignore
# Credentials - NEVER commit these
.env
servicenow_config.json
jamf_config.json

# Python cache
__pycache__/
*.pyc

# Node.js dependencies (reinstall with npm install)
node_modules/

# Logs
*.log

# OS files
.DS_Store

The example file pattern

Instead of committing real credentials, create example files with placeholder values:

servicenow_config.json

BLOCKED by .gitignore (never uploaded)

{
  "username": "jsmith",
  "password": "MyRealPassword123!"
}

servicenow_config.example.json

SAFE to commit (no real values)

{
  "username": "YOUR_USERNAME",
  "password": "YOUR_PASSWORD"
}

When a new team member clones the repo, they:

  1. Copy the example file: cp servicenow_config.example.json servicenow_config.json
  2. Fill in their own credentials
  3. The real file is automatically ignored by Git

What if I already committed a secret?

Act fast! If you accidentally committed credentials:
  1. Change the password immediately — assume it's been seen
  2. Add the file to .gitignore
  3. Remove it from Git tracking: git rm --cached filename
  4. Commit the removal and push

The old password will still be in Git history. For truly sensitive leaks, contact your team lead.

README files

Every repo should have a README.md file in the root folder. This is the first thing people see when they visit your repo on GitHub. It should include:

  • What the project does — a one-sentence description
  • How to set it up — install steps, dependencies, config files to create
  • How to run it — the command to start the app
  • Who maintains it — team or person responsible

Example:

README.md
# VIP Dashboard

Weekly VIP ticket tracking dashboard for Desktop Engineering.

## Setup
1. Clone the repo: `gh repo clone MercuryInsuranceEI/VIPDashboard`
2. Install dependencies: `npm install`
3. Copy `config.example.json` to `config.json` and fill in your credentials
4. Start the server: `node server.js`

## Maintained by
Desktop Engineering - Steve Cabrera
The .md extension means Markdown — a simple formatting language. # Heading, **bold**, - bullet. GitHub renders it nicely on the repo page.
12

VS Code GUI Method

Don't like the terminal? Use the GUI instead

VS Code has a built-in Git panel that lets you do everything visually — no terminal needed. Some people find this easier, especially when starting out.

Opening the Source Control panel

Click the branch icon in the left sidebar (third icon from top), or press:

Windows

Ctrl + Shift + G

Mac

Cmd + Shift + G

This opens the Source Control panel, which shows all your changed files. Here's what it looks like:

SOURCE CONTROL
✓ Commit
Staged Changes 1
M server.js src/
Changes 2
M config.js src/ +
U new_script.py +
↑ Type your commit message here
Green = staged (ready to commit)
↑ Click + to stage, to unstage

The GUI workflow (same 4 steps, just visual)

Step Terminal Command VS Code GUI Equivalent
1. See changes git status Open Source Control panel — changed files appear automatically
2. Stage files git add filename Click the + icon next to each file (or click + next to "Changes" to stage all)
3. Commit git commit -m "msg" Type your message in the text box at the top, then click the checkmark button
4. Push git push Click the ... menu → Push, or click the sync icon in the bottom status bar

Pulling updates in the GUI

Click the ... (three dots) menu at the top of the Source Control panel and select Pull. Or just click the sync icon (circular arrows) in the bottom-left status bar — this does both pull and push.

Viewing diffs

Click any changed file in the Source Control panel to see a side-by-side diff — the old version on the left, your changes on the right. This is one of the best features of VS Code's Git integration.

Resolving merge conflicts visually

When a conflict happens, VS Code highlights the conflicting sections and gives you clickable buttons:

  • Accept Current Change — keep your version
  • Accept Incoming Change — keep the other person's version
  • Accept Both Changes — keep both
  • Compare Changes — see them side by side

Click the option you want, save the file, stage it, and commit. Much easier than editing conflict markers by hand.

Terminal or GUI — your choice. Both methods do the exact same thing under the hood. Use whichever you're more comfortable with. Many people mix both — using the GUI for staging/committing and the terminal for pulling and branching.
13

GitHub Website

Half of Git happens in the browser

You've learned the terminal and VS Code — but a lot of Git collaboration happens on github.com. Here's a tour of what you'll actually use.

Your repo's home page

Go to github.com/MercuryInsuranceEI/RepoName and you'll see:

  • Code tab — Browse all files, click into folders, read any file right in the browser
  • README — Displayed automatically below the file list (this is why every repo needs one!)
  • Branch dropdown — Switch between branches to see different versions
  • Green "Code" button — Copy the clone URL

Viewing commit history

Click the "X commits" link (near the top of the Code tab) to see every change ever made:

  • Who made each change (author)
  • When it was made (timestamp)
  • The commit message (what they described)
  • Click any commit to see the exact lines that changed (the diff)

This is incredibly useful for understanding "who changed this and why?"

Key tabs on your repo

Tab What it's for
Code Browse files, view README, see branches
Issues Track bugs and feature requests. Like a to-do list for the project.
Pull requests See open PRs, review code, merge changes
Settings Manage who has access, branch protection rules, etc. (admin only)

Quick edits on GitHub

For tiny changes (typos, config updates), you can edit files directly on github.com without cloning:

  1. Navigate to the file on GitHub
  2. Click the pencil icon (edit) in the top-right of the file
  3. Make your change
  4. Write a commit message at the bottom and click "Commit changes"
For small edits only. For real development, always clone and work locally. Editing on GitHub is handy for quick fixes like updating a README or fixing a typo.

Staying in the loop: Notifications

GitHub can notify you when things happen in your repos:

  • Watch a repo: Click the "Watch" button at the top of any repo to get notified of PRs, issues, and comments
  • @ mentions: If someone tags you in a comment (@yourname), you get an email and a notification on github.com
  • PR reviews: You're automatically notified when someone requests your review
  • Bell icon: Click the bell at the top-right of github.com to see all your notifications
Tip: Go to github.com/settings/notifications to customize what sends you emails vs. just showing up on the website. Most people turn off email for everything except direct mentions and review requests.
14

Cheat Sheet

Everyday Commands

What you want to do Command
See what's changedgit status
Get latest changes from GitHubgit pull
Stage a filegit add filename
Stage all changesgit add .
Save a snapshotgit commit -m "description"
Upload to GitHubgit push
See commit historygit log --oneline
See what changed in a filegit diff filename

Setup Commands (one-time)

What you want to do Command
Log in to GitHubgh auth login
Set your namegit config --global user.name "Your Name"
Set your emailgit config --global user.email "you@mercury.com"
Clone a repogh repo clone OrgName/RepoName

Branch Commands

What you want to do Command
Create & switch to new branchgit checkout -b branch-name
Switch branchesgit checkout branch-name
List all branchesgit branch
Merge a branch into currentgit merge branch-name
Delete a branch (local)git branch -d branch-name

The Daily Workflow (copy this!)

Your daily routine
# Start of day — get latest
git pull

# After making changes
git status                          # See what changed
git add file1.py file2.js           # Stage specific files
git commit -m "What you changed"    # Save snapshot
git push                            # Upload to GitHub
15

Using Claude Code

Let Claude do the Git work for you

Claude Code is an AI assistant that runs in your terminal. It can handle Git operations for you — just describe what you want in plain English. No need to memorize commands.

What Claude Code can do with Git

  • Stage, commit, and push your changes
  • Write good commit messages based on what you actually changed
  • Pull updates and resolve merge conflicts
  • Create branches and switch between them
  • Show you what changed and explain diffs
  • Set up .gitignore files
  • Fix mistakes (undo commits, unstage files, etc.)

Example prompts you can use

What you want to do What to tell Claude
Push your work to GitHub "Commit and push my changes"
See what you changed "What files have I changed?"
Get latest from GitHub "Pull the latest changes"
Work on a new feature separately "Create a new branch called fix-login-bug"
Undo your last commit "Undo my last commit but keep the changes"
Fix a merge conflict "I have a merge conflict, help me resolve it"
Set up a .gitignore "Create a .gitignore for a Node.js project"
Understand what happened "Show me the last 5 commits and what changed"

Using the /commit shortcut

Claude Code has a built-in shortcut for committing. Just type:

In Claude Code
/commit

Claude will automatically:

  1. Look at all your changes
  2. Write a clear commit message describing what changed
  3. Stage the relevant files and commit

You review the message before it's finalized — Claude won't push without your approval.

Tips for working with Claude Code

  • Be specific: "Commit just the server.js changes" is better than "commit stuff"
  • Ask questions: "What would happen if I push right now?" — Claude can explain before acting
  • Let Claude explain: "Explain what git rebase does in simple terms" — great for learning
  • Review before pushing: Claude always shows you what it's about to do — read and approve before it runs
Claude Code doesn't replace learning Git. It's a great assistant that saves time, but understanding the basics (this training!) helps you know what Claude is doing and catch mistakes. Think of it as a copilot, not autopilot.
16

Troubleshooting

Something went wrong? Start here.

These are the most common errors you'll see. Don't panic — every one of these has a simple fix.

"fatal: not a git repository"

What happened: You ran a git command in a folder that isn't a Git repo.

fatal: not a git repository (or any of the parent directories): .git

Fix: Make sure you cd into your project folder first:

Terminal
cd RepoName
git status    # should work now

"Your branch is behind 'origin/main'"

What happened: Someone pushed changes to GitHub that you don't have yet.

Your branch is behind 'origin/main' by 3 commits, and can be fast-forwarded.

Fix: Just pull:

Terminal
git pull

"rejected - failed to push some refs"

What happened: You tried to push, but GitHub has changes you don't have locally.

! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/...'
hint: Updates were rejected because the remote contains work that you do not have locally.

Fix: Pull first, then push:

Terminal
git pull
git push

If the pull creates a merge conflict, see the Merge Conflicts section.

"Permission denied" or "authentication failed"

What happened: Git can't log in to GitHub. Your credentials may have expired.

remote: Permission to MercuryInsuranceEI/RepoName.git denied to yourname.
fatal: unable to access 'https://github.com/...'

Fix: Re-authenticate with GitHub CLI:

Terminal
gh auth login

Follow the prompts (same as the Account Setup section). If it still fails, check that you've been added to the MercuryInsuranceEI GitHub organization.

"You have divergent branches"

What happened: You and someone else both made commits, and Git doesn't know how to combine them.

hint: You have divergent branches and need to specify how to reconcile them.

Fix: Tell Git to merge (the default, safest option):

Terminal
git pull --no-rebase

To avoid this message in the future, set the default once:

Terminal (one-time fix)
git config --global pull.rebase false

"Changes not staged for commit" when you try to commit

What happened: You forgot to git add before committing.

nothing added to commit but untracked files present (use "git add" to track)

Fix: Stage your files first:

Terminal
git add filename.js
git commit -m "Your message"

The nuclear option: start fresh

If everything is completely broken and you just want a clean slate:

Terminal
# Go up one directory
cd ..

# Delete the broken folder (WARNING: you lose un-pushed local changes!)
rm -rf RepoName        # Mac / Git Bash
rmdir /s RepoName      # Windows CMD

# Clone fresh from GitHub
gh repo clone MercuryInsuranceEI/RepoName
cd RepoName
Only do this if you've pushed your important changes. Anything you committed and pushed is safe on GitHub. Anything only on your local machine will be lost.
17

FAQ

I made changes but don't want to keep them. How do I undo?

If you haven't committed yet:

git checkout -- filename

This reverts the file back to the last committed version.

If you already committed but haven't pushed:

git reset --soft HEAD~1

This undoes the last commit but keeps your changes so you can re-do it.

I accidentally committed a file with passwords. What do I do?

Step 1: Change the password immediately.

Step 2: Add the file to .gitignore

Step 3: Remove from tracking:

git rm --cached servicenow_config.json
git commit -m "Remove credentials file from tracking"
git push
What's the difference between git add . and git add filename?

git add . stages EVERYTHING that changed. git add filename stages just that one file.

Using specific filenames is safer because you won't accidentally include files you didn't mean to (like .env or test files).

Do I need to commit every time I save a file?

No! Save your files normally as you work. Only commit when you've reached a good stopping point — like finishing a feature, fixing a bug, or at the end of the day.

Think of commits as checkpoints, not autosave.

Can I use VS Code instead of the terminal?

Yes! VS Code has built-in Git support. Click the branch icon in the left sidebar to:

  • See changed files
  • Stage changes (click the + icon)
  • Write commit messages and commit
  • Push/pull with the sync button

The terminal commands are shown in this training because they work everywhere, but VS Code's GUI does the same thing.

What if I mess everything up?

The nuclear option: delete the folder and re-clone. Since everything is on GitHub, you can always start fresh:

cd ..
rm -rf ProjectFolder
gh repo clone OrgName/RepoName

You'll lose any un-pushed local changes, but you'll have a clean copy of whatever's on GitHub.

How do I see who changed a specific line of code?
git blame filename

This shows who last modified each line, when, and in which commit. Great for understanding why something was changed.

You made it!

You now know enough Git to work with your team. Remember:

  • Pull before you start working
  • Commit often with clear messages
  • Push when you're ready to share
  • Never commit passwords
  • When in doubt, git status

Bookmark this page and refer back to the Cheat Sheet whenever you need it.