Git and GitHub Complete Guide for Beginners — 2026 Edition
Master Git and GitHub from scratch — init, commit, branches, merging, pull requests and team workflows. The only guide you need for version control in 2026.
Get more content like this on Telegram!
Daily AI tips, notes & resources — free
Git and GitHub Complete Guide for Beginners
Git is the most important tool a developer uses after their code editor. Without version control, you're one mistake away from losing everything. With Git, every change is tracked, every mistake is reversible, and collaboration becomes effortless. If you're just starting out, first follow our web development roadmap — Git fits naturally into that learning path.
What is Git?
Git is a distributed version control system — it tracks every change you make to your code over time. Think of it as a time machine for your code.
Why every developer needs Git:
- Undo any mistake — revert to any previous state
- Work on multiple features simultaneously with branches
- Collaborate with teams without overwriting each other's work
- Track who changed what and why
- Deploy code safely with rollback capability
Setting Up Git
# Install Git (macOS with Homebrew)
brew install git
# Install Git (Ubuntu/Debian)
sudo apt install git
# Verify installation
git --version # git version 2.44.0
# Configure your identity (required!)
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global core.editor "code --wait" # VS Code as editor
# Check configuration
git config --list
Core Git Workflow
# 1. Initialize a new repository
mkdir my-project && cd my-project
git init
# 2. Create some files
echo "# My Project" > README.md
echo "print('Hello World')" > main.py
# 3. Check status — see what's changed
git status
# 4. Stage files for commit
git add README.md main.py
# or stage everything:
git add .
# 5. Commit with a meaningful message
git commit -m "feat: initial project setup with README and main script"
# 6. View commit history
git log --oneline
Branching — The Power Feature
# Create and switch to a new branch
git checkout -b feature/user-authentication
# Make changes on the branch
echo "def authenticate(user): pass" >> auth.py
git add auth.py
git commit -m "feat: add authentication placeholder"
# List all branches
git branch -a
# Switch back to main
git checkout main
# Merge the feature branch
git merge feature/user-authentication
# Delete the feature branch after merging
git branch -d feature/user-authentication
Working with GitHub
# 1. Create a repo on GitHub (github.com)
# 2. Connect your local repo to GitHub
git remote add origin https://github.com/yourusername/my-project.git
# 3. Push your code to GitHub
git push -u origin main
# 4. Pull latest changes from GitHub
git pull origin main
# 5. Clone an existing repo
git clone https://github.com/username/repo-name.git
The Pull Request Workflow
Pull Requests (PRs) are the backbone of team collaboration:
# 1. Create a feature branch
git checkout -b feat/add-search
# 2. Make changes and commit
git add .
git commit -m "feat: implement search functionality"
# 3. Push the branch to GitHub
git push origin feat/add-search
# 4. On GitHub: Open a Pull Request
# - Compare feat/add-search → main
# - Add description and reviewers
# - Request review from teammates
# 5. After approval: Merge the PR
# 6. Delete the branch on GitHub
# 7. Pull the updated main locally
git checkout main
git pull origin main
Essential Git Commands Cheat Sheet
# Status & Info
git status # See changed files
git log --oneline # Compact commit history
git diff # See unstaged changes
git diff --staged # See staged changes
# Undoing Mistakes
git restore file.py # Discard unstaged changes
git restore --staged file.py # Unstage a file
git revert HEAD # Undo last commit (safe)
git reset --hard HEAD~1 # Delete last commit (dangerous!)
# Stashing
git stash # Save work-in-progress
git stash pop # Restore stashed work
git stash list # List all stashes
# Remote Operations
git fetch origin # Download changes (don't merge)
git pull origin main # Download + merge
git push origin main # Upload local commits
# Branch Operations
git branch # List branches
git branch -d name # Delete branch
git checkout -b name # Create + switch
git merge branch-name # Merge branch into current
Commit Message Best Practices
Good commit messages tell a story. Use the Conventional Commits standard:
# Format: type(scope): description
feat: add user login functionality
fix: resolve database connection timeout
docs: update README with installation steps
style: format code with prettier
refactor: extract authentication logic
test: add unit tests for user model
chore: update dependencies to latest versions
.gitignore — What to Exclude
# Create .gitignore at root
touch .gitignore
# Dependencies
node_modules/
.venv/
__pycache__/
# Environment variables
.env
.env.local
.env.production
# Build outputs
dist/
build/
.next/
out/
# IDE files
.vscode/settings.json
.idea/
# OS files
.DS_Store
Thumbs.db
# Logs
*.log
npm-debug.log*
Git with AI Tools in 2026
GitHub Copilot can help you write better commit messages and resolve conflicts:
# Use GitHub Copilot CLI for commit messages
gh copilot suggest "write a commit message for adding user authentication"
# Use AI to explain a confusing commit
git show abc1234 | gh copilot explain
Git is a lifelong skill. Start using it today on every project — even personal ones. The habits you build now will serve you throughout your entire career.
GitHub — Hosting Your Code Online
Git manages your code locally. GitHub hosts it online and enables collaboration.
# 1. Create a new repo on GitHub (github.com → New Repository)
# 2. Connect your local repo to GitHub
git remote add origin https://github.com/username/my-project.git
# 3. Push your code for the first time
git push -u origin main
# 4. For subsequent pushes
git push
# 5. Clone someone else's repo
git clone https://github.com/username/project.git
Pull Requests — How Teams Collaborate
A Pull Request (PR) is the standard way to propose code changes on GitHub:
- Create a feature branch from main
- Make your changes and commit them
- Push the branch to GitHub
- Open a Pull Request on GitHub — describe what you changed and why
- Team reviews the code, leaves comments, requests changes
- Merge when approved
# Full PR workflow
git checkout -b feature/add-search-bar # Create feature branch
# ... make changes ...
git add .
git commit -m "feat: add search bar to header navigation"
git push origin feature/add-search-bar # Push branch to GitHub
# → Open PR on GitHub via the web interface
Good PR descriptions include:
- What changed
- Why it was needed
- How to test the change
- Screenshots for UI changes
Resolving Merge Conflicts
Merge conflicts happen when two people edit the same lines of the same file. They look frightening but are easy to resolve once you understand them.
# Start a merge that has conflicts
git merge feature/team-member-branch
# Git will show conflicted files
git status
# both modified: src/components/Header.tsx
# Open the file — look for conflict markers:
// In the conflicted file:
<<<<<<< HEAD
const headerColor = 'blue'; // your version
=======
const headerColor = 'purple'; // incoming version
>>>>>>> feature/team-member-branch
To resolve:
- Delete the conflict markers (
<<<<<<<,=======,>>>>>>>) - Keep the version you want (or combine them)
- Save the file
git add src/components/Header.tsxgit commit -m "fix: resolve merge conflict in Header component"
VS Code has a built-in merge conflict UI that makes this visual — click "Accept Current Change", "Accept Incoming Change", or "Accept Both Changes" directly in the editor.
Advanced Git Commands
Once you're comfortable with the basics, these commands become invaluable:
Git Stash — Save Work in Progress
# Stash your current changes (temporarily shelve them)
git stash push -m "work in progress on search feature"
# See all stashes
git stash list
# Re-apply the most recent stash
git stash pop
# Apply a specific stash
git stash apply stash@{1}
Use case: You're in the middle of a feature when an urgent bug fix comes in. Stash your work, fix the bug, then pop the stash to continue.
Git Rebase — Cleaner History
# Rebase your feature branch onto main
git checkout feature/my-feature
git rebase main
# Interactive rebase — squash, rename, reorder commits
git rebase -i HEAD~3 # Interactively edit last 3 commits
Rebase creates a linear commit history instead of the messy merge commits. Most teams prefer rebased PRs for cleaner git log output.
Git Cherry-Pick — Apply Specific Commits
# Apply a specific commit from another branch
git cherry-pick abc1234
# Apply multiple commits
git cherry-pick abc1234 def5678
Use case: A colleague committed a useful utility function on their branch. Cherry-pick just that commit onto yours without taking their whole branch.
GitHub Actions — CI/CD Automation
GitHub Actions automates testing, building, and deployment directly from your repository.
# .github/workflows/test.yml
name: Run Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20'
- run: npm install
- run: npm test
- run: npm run build
This workflow automatically runs your tests on every push and pull request. If tests fail, the PR shows a red ❌ and cannot be merged. This is continuous integration — the standard in professional teams.
Git for Teams — Best Practices
Branching Strategy (Git Flow)
Most teams follow a convention:
main— production-ready code onlydevelop— integration branch for featuresfeature/name— individual featuresfix/issue-name— bug fixesrelease/version— release preparation
Writing Great Commit Messages
The Conventional Commits standard makes your history readable and enables automated changelogs:
# Format: type(scope): description
feat: add OAuth Google login
fix(auth): resolve token expiration bug
docs: add API authentication documentation
style: format components with Prettier
refactor(api): extract request handling to utils
test: add integration tests for user registration
chore: upgrade TypeScript to v5.4
perf(db): add index to users email field
The 7 rules of a great commit message:
- Limit the subject line to 72 characters
- Use the imperative mood ("add feature" not "added feature")
- Don't end with a period
- Separate body from subject with a blank line
- Explain what and why, not how
- Reference issue numbers when relevant (
fix #123)
Code Review Checklist
When reviewing PRs, check:
- Does the code do what the PR says it does?
- Are there tests for the new functionality?
- Are there any edge cases not handled?
- Is the code readable and well-named?
- Does it follow the project's conventions?
Git Aliases — Speed Up Your Workflow
# Add these to your ~/.gitconfig
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --decorate"
git config --global alias.unstage "reset HEAD --"
# Now you can use:
git st # instead of git status
git co main # instead of git checkout main
git lg # beautiful log visualization
The Git Mental Model
After learning all these commands, the key is to internalize one mental model:
Git tracks snapshots, not differences. Every commit is a complete snapshot of your entire project at that moment. When you branch, you create a parallel timeline. When you merge, you reconcile two timelines. When you rebase, you rewrite one timeline to grow from a different point.
With this model, complex Git operations become intuitive. Merge conflict? Two timelines disagree about the same code — you decide what the reconciled version looks like. Rebase? You're replaying your commits as if you'd started from a different point in history.
Git Cheat Sheet
| Command | What it Does |
|---|---|
git init | Initialize a repository |
git clone [url] | Download a remote repository |
git status | Show working tree status |
git add . | Stage all changes |
git commit -m "msg" | Commit with message |
git push | Push to remote |
git pull | Pull from remote |
git checkout -b name | Create + switch branch |
git merge branch | Merge branch into current |
git log --oneline | View commit history |
git diff | Show unstaged changes |
git stash | Shelve current changes |
git reset HEAD~1 | Undo last commit (keep changes) |
git revert abc123 | Create undo commit |
Git is genuinely a lifelong skill — professionals use it every single day and still learn new tricks years in. Start using it on every project, no matter how small.
Next steps: Pair Git with Python for beginners or JavaScript & React to build real projects with proper version control. Explore our free programming notes library for cheat sheets on every tool covered here.
Get Git cheat sheets and coding tips free on our Telegram channel!
Frequently Asked Questions
AiTechWorlds Team
✓ Verified WriterThe AiTechWorlds team is passionate about AI, technology, and education. We create high-quality, research-backed content to help you learn, grow, and succeed in the modern digital world.
Related Articles
Python OOP Complete Guide 2026 — Object-Oriented Programming Mastery
Master Python object-oriented programming from basics to advanced. Classes, inheritance, polymorphism, SOLID principles, dataclasses — everything you need to write professional Python.
Python Error Handling & Debugging 2026 — Write Bulletproof Code
Master Python error handling and debugging techniques. Learn try/except, custom exceptions, logging, pdb, and professional debugging strategies to write robust Python code.
Python Decorators and Generators — Advanced Python Made Simple 2026
Master Python decorators and generators — two of Python's most powerful features. Clear explanations, real-world examples, and practical patterns you'll actually use.
Python Testing with pytest 2026 — From Beginner to Pro Guide
Learn Python testing with pytest from scratch. Write unit tests, integration tests, use fixtures and mocks, measure coverage — everything a professional Python developer needs.