Git and GitHub for Beginners 2026: Complete Guide
Learn Git and GitHub from scratch - repositories, commits, branches, pull requests, and collaboration workflows explained step by step.
Git is the version control system every developer uses. GitHub is where your code lives online. Together, they are the foundation of modern software development.
This guide teaches you Git and GitHub from absolute zero - no prior experience needed.
Why You Need Git and GitHub
- Every tech company uses Git - it is a non-negotiable skill
- Track changes - see every edit you have ever made to your code
- Undo mistakes - go back to any previous version instantly
- Collaboration - work on the same code with a team without conflicts
- Portfolio - your GitHub profile is your developer resume
- Open source - contribute to projects used by millions
What Is Git?
Git is a version control system - it tracks every change you make to your files. Think of it as "save states" for your code.
Without Git:
- project-final.js
- project-final-v2.js
- project-REALLY-final.js
- project-final-final-USE-THIS.js
With Git:
- One project folder with complete history of every change
- Go back to any version with one command
- See who changed what and when
What Is GitHub?
GitHub is a cloud platform that hosts your Git repositories online. It adds collaboration features like pull requests, issues, and project boards.
Git = local tool on your computer GitHub = online platform to share and collaborate
Other alternatives: GitLab, Bitbucket - but GitHub is the most popular with 100+ million developers.
Step 1: Installation
Install Git
Windows: Download from git-scm.com. Run the installer with default settings.
Mac:
brew install git
Or install Xcode Command Line Tools: xcode-select --install
Linux:
sudo apt install git # Ubuntu/Debian
sudo dnf install git # Fedora
Verify installation:
git --version
# git version 2.45.0
Configure Git
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git config --global init.defaultBranch main
Create a GitHub Account
Go to github.com and sign up for free. Choose a professional username - this becomes your developer identity.
Step 2: Core Git Concepts
Repository (Repo)
A repository is a folder tracked by Git. It contains your project files and the complete history of changes.
Commit
A commit is a snapshot of your project at a specific point in time. Each commit has a message describing what changed.
Think of commits as save points in a video game - you can always go back to any save point.
Branch
A branch is a separate line of development. The main branch is your primary codebase. Create new branches to work on features without affecting main.
Remote
A remote is the online copy of your repository (on GitHub). You push changes to the remote and pull changes from it.
Step 3: Your First Repository
Create a Local Repository
# Create a new project folder
mkdir my-first-repo
cd my-first-repo
# Initialize Git tracking
git init
# Create a file
echo "# My First Project" > README.md
# Check status (shows untracked files)
git status
# Stage the file (prepare for commit)
git add README.md
# Commit (save the snapshot)
git commit -m "Initial commit: add README"
Push to GitHub
- Go to GitHub → New Repository
- Name it "my-first-repo"
- Do NOT initialize with README (you already have one)
- Copy the commands GitHub gives you:
git remote add origin https://github.com/yourusername/my-first-repo.git
git push -u origin main
Your code is now on GitHub!
Step 4: The Git Workflow
The daily workflow every developer follows:
1. git pull → Get latest changes from team
2. Make your changes → Edit code, add files
3. git add . → Stage all changed files
4. git commit -m "" → Save snapshot with message
5. git push → Upload to GitHub
Essential Commands
| Command | What It Does |
|---|---|
git init | Initialize a new repository |
git clone <url> | Download a repository from GitHub |
git status | Show changed/staged/untracked files |
git add . | Stage all changes for commit |
git add <file> | Stage a specific file |
git commit -m "msg" | Save staged changes with message |
git push | Upload commits to GitHub |
git pull | Download and merge remote changes |
git log | View commit history |
git diff | Show unstaged changes |
git branch | List all branches |
git checkout -b <name> | Create and switch to new branch |
git merge <branch> | Merge a branch into current branch |
Step 5: Branching
Branches let you work on features without breaking the main code.
Create and Use a Branch
# Create a new branch and switch to it
git checkout -b feature/add-login
# Make your changes...
# Then commit
git add .
git commit -m "Add login page"
# Push the branch to GitHub
git push -u origin feature/add-login
# When done, switch back to main
git checkout main
# Merge the feature branch
git merge feature/add-login
# Push the updated main
git push
Branch Naming Conventions
feature/add-login- new featuresfix/navbar-bug- bug fixesrefactor/cleanup-utils- code cleanupdocs/update-readme- documentation
Step 6: Pull Requests (PRs)
Pull requests are GitHub's way of reviewing code before merging.
How Pull Requests Work
- Create a feature branch and push your changes
- On GitHub, click "New Pull Request"
- Select your branch → main
- Add a title and description
- Request reviewers
- Reviewers comment, suggest changes, or approve
- Merge the PR when approved
- Delete the feature branch
Writing Good PR Descriptions
## What this PR does
Added user login page with email/password authentication.
## Changes
- Created LoginForm component
- Added /api/auth/login route
- Added input validation
- Added error handling for invalid credentials
## How to test
1. Go to /login
2. Enter test@example.com / password123
3. Should redirect to dashboard
Step 7: Handling Merge Conflicts
Conflicts happen when two people edit the same line of code. Git cannot decide which version to keep, so you resolve it manually.
What a conflict looks like:
<<<<<<< HEAD
const greeting = "Hello World";
=======
const greeting = "Hi there";
>>>>>>> feature/new-greeting
How to resolve:
- Open the conflicting file
- Choose which version to keep (or combine both)
- Remove the conflict markers (<<<, ===, >>>)
- Stage and commit the resolution
# After fixing the conflict
git add .
git commit -m "Resolve merge conflict in greeting"
VS Code tip: VS Code shows conflict resolution buttons - "Accept Current", "Accept Incoming", "Accept Both" - click to resolve without manual editing.
Step 8: .gitignore
The .gitignore file tells Git which files to NOT track. Never commit sensitive data or generated files.
Essential .gitignore for web projects:
# Dependencies
node_modules/
# Environment variables (NEVER commit these)
.env
.env.local
.env.production
# Build output
.next/
dist/
build/
# OS files
.DS_Store
Thumbs.db
# IDE settings
.vscode/
.idea/
Create .gitignore BEFORE your first commit to avoid accidentally committing node_modules or secrets.
Step 9: GitHub Profile Tips
Your GitHub profile is your developer resume. Make it stand out:
- Pin your best 6 repositories - show your best work
- Write good READMEs - every project needs description, setup instructions, and screenshots
- Contribute consistently - the green contribution graph shows activity
- Add a profile README - create a repo named your username with a README.md
- Use topics/tags - add language and framework tags to repos
- Star and fork interesting projects - shows your interests
- Contribute to open source - proves collaboration skills
Common Git Mistakes and Fixes
Accidentally committed wrong files
git reset HEAD~1 # Undo last commit (keep changes)
# Fix the files, then commit again
Committed to wrong branch
git stash # Save changes temporarily
git checkout correct-branch
git stash pop # Apply saved changes here
Need to update commit message
git commit --amend -m "New correct message"
Accidentally deleted a file
git checkout -- filename # Restore file from last commit
Want to undo all local changes
git checkout -- . # Discard all unstaged changes
Git Workflow for Teams
Feature Branch Workflow (Most Common)
main (production-ready code)
└── feature/user-auth (your feature)
└── feature/payment (teammate's feature)
└── fix/login-bug (bug fix)
Rules:
- Never commit directly to main
- Create a branch for every feature/fix
- Open a PR for review
- Merge only after approval
- Delete branch after merging
Related ByteVerse guides
Next, read JavaScript Roadmap 2026, How to Learn Programming 2026, Best VS Code Extensions 2026, and Best AI Coding Assistants 2026 to explore more.
If you're on Windows, consider setting up WSL for a proper terminal experience - Git commands feel more natural in a Linux environment.
Frequently Asked Questions
Is Git hard to learn?
The basics (init, add, commit, push, pull) take 1-2 hours to learn. Branching and pull requests take a few days of practice. Advanced features (rebasing, cherry-picking) take weeks but are rarely needed as a beginner.
Do I need Git for personal projects?
Yes. Even solo projects benefit from version control. You can undo mistakes, track your progress, and your GitHub profile serves as your portfolio. Start using Git for every project from day one.
What is the difference between Git and GitHub?
Git is a version control tool installed on your computer. GitHub is a cloud platform that hosts Git repositories online and adds collaboration features like pull requests and issues. You can use Git without GitHub but not GitHub without Git.
How often should I commit?
Commit after every meaningful change - completing a feature, fixing a bug, or reaching a working state. Small, frequent commits with clear messages are better than large, infrequent ones.
Can I use Git with VS Code?
Yes. VS Code has excellent built-in Git support - staging, committing, branching, and resolving conflicts all work through the UI. The GitLens extension adds even more features like inline blame and file history.
Is GitHub free?
Yes. Free accounts get unlimited public and private repositories, unlimited collaborators, and 2,000 GitHub Actions minutes per month. Paid plans add features like protected branches and advanced security.
Share this article