
The Complete Guide to
GitHub
Learn how to create repositories, push code, manage branches, collaborate with teams, and master the Git workflow — from absolute zero to confident contributor.
Start Reading ↓What Is GitHub & Why Should You Care?
Git is a distributed version control system that tracks every change you make to your code. Think of it as an “unlimited undo” button for your entire project — you can jump back to any point in time, see who changed what, and safely experiment without breaking things.
GitHub is a cloud platform built on top of Git. It hosts your repositories (projects) online, adds collaboration tools like pull requests, issues, and actions, and serves as the world’s largest developer community. Whether you’re building a personal project or contributing to open source, GitHub is where modern software lives.
Setting Up Git & GitHub
Step A — Install Git
Download Git from git-scm.com. On macOS you can also use Homebrew; on most Linux distros, Git comes pre-installed.
# Check if Git is installed git --version # macOS with Homebrew brew install git # Ubuntu / Debian sudo apt install git
Step B — Create a GitHub Account
Head to github.com and sign up for a free account. Choose a username you’ll be proud of — it becomes part of your public developer identity.
Step C — Configure Git Locally
Tell Git who you are. This information gets attached to every commit you make.
git config --global user.name "Your Name" git config --global user.email "you@example.com" # Verify your settings git config --list
Step D — Set Up SSH Authentication (Recommended)
SSH keys let you push and pull code without typing your password every time.
# Generate a new SSH key ssh-keygen -t ed25519 -C "you@example.com" # Copy the public key to your clipboard cat ~/.ssh/id_ed25519.pub # Then paste it into GitHub → Settings → SSH Keys
Creating Your First Repository
A repository (or “repo”) is a project folder that Git tracks. You can create one on GitHub’s website, from the command line, or both.
Option 1 — Create on GitHub, Clone Locally
git clone git@github.com:your-username/my-project.git cd my-project
Option 2 — Start Locally, Push to GitHub
# Create a folder and initialize Git mkdir my-project && cd my-project git init # Create a file and make your first commit echo "# My Project" > README.md git add README.md git commit -m "Initial commit" # Link to GitHub and push git remote add origin git@github.com:your-username/my-project.git git push -u origin main
The Core Git Workflow
Day-to-day Git boils down to a simple loop. Understanding this cycle is the single most important thing to internalize.
# 1. Check what's changed git status # 2. Stage specific files (or all changes) git add index.html style.css git add . # stage everything # 3. Commit with a descriptive message git commit -m "Add responsive nav bar" # 4. Push to GitHub git push
Branching & Merging
Branches let you work on features, fixes, or experiments in isolation without touching the stable main branch. This is what makes team collaboration possible — everyone works on their own branch, then merges when ready.
# Create and switch to a new branch git checkout -b feature/user-auth # See all branches (* = current) git branch # Switch between branches git checkout main # Merge a branch into main git checkout main git merge feature/user-auth # Delete a branch after merging git branch -d feature/user-auth
Pull Requests & Collaboration
A Pull Request (PR) is GitHub’s way of saying “Hey team, I’ve got changes ready — please review and merge them.” It’s the heart of collaboration on GitHub.
Creating a Pull Request
Contributing to Other Projects (Fork & PR)
Want to contribute to someone else’s open-source repo? The workflow is: Fork → Clone → Branch → Change → Push → PR.
# 1. Fork the repo on GitHub (click "Fork" button) # 2. Clone YOUR fork git clone git@github.com:your-username/forked-repo.git # 3. Add original repo as "upstream" git remote add upstream git@github.com:original-owner/repo.git # 4. Create a branch, make changes, push to YOUR fork git checkout -b fix/typo-in-readme # ... make changes ... git push origin fix/typo-in-readme # 5. Open a PR from your fork to the original repo
Updating & Syncing Changes
When other people push changes, you need to pull them down. When your branch falls behind main, you need to rebase or merge. Here are the essential commands.
# Pull the latest changes from the remote git pull # Pull with rebase (cleaner history) git pull --rebase # Update your feature branch with latest main git checkout feature/my-work git rebase main # If you're working on a fork, sync with upstream git fetch upstream git rebase upstream/main
Handling Merge Conflicts
Conflicts happen when two people edit the same line. Git will mark the conflicts in your files with <<<<<<< markers. To resolve them:
- Open the conflicted file and find the conflict markers.
- Choose which version to keep (or combine both), and delete the markers.
- Stage the resolved file with git add and continue.
# After fixing the conflict in your editor: git add conflicted-file.js git rebase --continue # or if merging: git commit
Essential GitHub Features
Issues
GitHub Issues are your project’s task tracker. Use them to report bugs, request features, or track to-dos. You can label them, assign team members, and link them to PRs with keywords like Fixes #42 in your commit message.
GitHub Actions (CI/CD)
Automate testing, building, and deploying your code. Actions run workflows triggered by events like pushes or PRs. A workflow is defined in a YAML file inside .github/workflows/.
GitHub Pages
Host static websites directly from a repo — perfect for portfolios, documentation, and project landing pages. Enable it in your repo’s settings under “Pages.”
The .gitignore File
This file tells Git which files and folders to ignore — things like node_modules/, environment files (.env), and build artifacts. GitHub provides templates for every major language at github/gitignore.
README.md
Your repo’s front page. A great README includes a project description, installation instructions, usage examples, and contribution guidelines. It’s the first thing visitors see — make it count.
Best Practices & Pro Tips
Quick Command Reference
# ── Setup ── git init # Initialize new repo git clone <url> # Clone existing repo # ── Daily Work ── git status # See changes git add . # Stage all changes git commit -m "message" # Commit staged changes git push # Upload to GitHub git pull # Download latest changes # ── Branching ── git branch # List branches git checkout -b branch-name # Create & switch branch git merge branch-name # Merge branch into current git branch -d branch-name # Delete branch # ── History & Inspection ── git log --oneline # Compact commit history git diff # See unstaged changes git stash # Temporarily shelve changes git stash pop # Restore shelved changes # ── Undo ── git checkout -- file.txt # Discard file changes git reset HEAD~1 # Undo last commit (keep files) git revert <commit-hash> # Create undo commit


Comments are closed.