Git and GitHub for Beginners: From Zero to Your First Pull Request

Every developer uses Git. It is the universal language of code collaboration. But learning Git can feel like memorizing a spellbook — add, commit, push, pull, merge, rebase, stash… What do all these words mean?

This guide cuts through the noise. You learn the 8 commands that cover 95% of your daily Git usage — and you make your first GitHub pull request by the end of this guide.

1. What Is Git? (30 Seconds)

Git tracks changes to your files. It lets you save versions of your code, go back to any previous version, and collaborate with others without overwriting each other's work.

GitHub is a website that stores Git repositories in the cloud. It adds collaboration features — pull requests, issues, project boards — on top of Git.

Git is the tool. GitHub is the platform. You use Git on your computer. You use GitHub in your browser.

2. Installing Git

# macOS
brew install git

# Windows
# Download from https://git-scm.com/download/win

# Linux (Ubuntu/Debian)
sudo apt install git

# Verify
git --version
# git version 2.45.0

3. Configuring Git (First Time Only)

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

# Optional: set default branch name to main
git config --global init.defaultBranch main

4. Your First Repository

Create a New Project

mkdir my-project
cd my-project
git init                     # Initialize a Git repository
echo "# My Project" > README.md
git add README.md            # Stage the file
git commit -m "First commit" # Save the change

That is the core Git loop: change files → stage (add) → commit. Everything else builds on this.

5. The 8 Commands You Will Use Every Day

CommandWhat It DoesWhen to Use
git statusShows what files have changedBefore every commit
git add .Stages all changesBefore committing
git commit -m "msg"Saves staged changesAfter staging
git pushUploads commits to GitHubAfter committing
git pullDownloads changes from GitHubBefore starting work
git branchLists / creates branchesStarting new features
git checkout -b nameCreates + switches to a new branchStarting new features
git merge branchMerges branch into currentAfter finishing a feature

6. Push to GitHub (First Time)

⚠ Watch out: GitHub no longer accepts password authentication for Git operations. You must use a personal access token (PAT) or SSH key. Generate a token at github.com/settings/tokens with "repo" scope, and use it as your password when prompted.

Step 1: Create a GitHub Repository

Go to github.com/new. Give it a name. Do NOT check "Add a README" (you already have one). Click "Create repository."

Step 2: Link Your Local Repo to GitHub

git remote add origin https://github.com/YOUR-USERNAME/my-project.git
git branch -M main
git push -u origin main

Refresh your GitHub page. Your code is there.

7. Branches: Work on Features Without Breaking Main

Branches let you work on new features in isolation. The main branch always has working code. Feature work happens on separate branches.

# Create and switch to a new branch
git checkout -b add-dark-mode

# Make changes...
# (edit files, add new features)

git add .
git commit -m "Add dark mode toggle"
git push origin add-dark-mode

8. Your First Pull Request

A pull request (PR) is a request to merge your branch into main. It is where code review happens.

Step by Step:

  1. Push your feature branch to GitHub
  2. Go to your repository on GitHub
  3. Click "Compare & pull request" (GitHub shows this automatically after you push)
  4. Write a title and description of what you changed
  5. Click "Create pull request"
  6. Wait for review (or merge it yourself if you are solo)
  7. Click "Merge pull request"
  8. Delete the branch (GitHub offers a button)

After merging on GitHub, update your local main:

git checkout main
git pull origin main

9. Your Daily Git Workflow

# 1. Start the day: get latest changes
git checkout main
git pull origin main

# 2. Create a branch for your task
git checkout -b fix-login-bug

# 3. Work, save, commit (repeat)
# ... edit files ...
git status
git add .
git commit -m "Fix login redirect bug"

# 4. Push and create PR
git push origin fix-login-bug

# 5. Create pull request on GitHub

This is the complete workflow. Master it and you are a productive Git user.

10. Common Mistakes and How to Fix Them

\"I committed to the wrong branch\"

# Undo the last commit (keeps changes)
git reset --soft HEAD~1

# Switch to the correct branch
git checkout -b correct-branch

# Re-commit
git add .
git commit -m "Correct commit"

\"I want to undo all local changes\"

git checkout .  # Discard all unstaged changes

\"Merge conflict!\"

ⓘ Tip: Most merge conflicts are small — a few lines. Read the markers carefully before deciding what to keep. When in doubt, use git merge --abort to back out and start over.

Git tells you which files conflict. Open them, look for <<<<<<<, =======, >>>>>>> markers. Decide which version to keep, remove the markers, save, then:

git add .
git commit -m "Resolve merge conflict"

Git is not hard — you just need to learn the right 8 commands and the daily workflow. The rest you look up when you need it.

Frequently Asked Questions

What is the difference between Git and GitHub?

Git is the version control software that runs on your computer. GitHub is a cloud platform that hosts Git repositories and adds collaboration tools.

Should I use the command line or a GUI?

Learn the command line first. It works everywhere, all tutorials use it, and once you know CLI you can use any GUI (GitHub Desktop, GitKraken, VS Code Git) with full understanding.

What is a .gitignore file?

A file that tells Git which files to ignore (node_modules, .env, build artifacts, etc.). Create one at the root of your project. GitHub provides templates for every language.