Imagine you’re writing a novel. You want to save every version, experiment with different endings, and maybe collaborate with other writers. But instead of having dozens of files named “novel_final_v2_really_final_final.doc,” you have a smart system that tracks everything for you.
Git and GitHub are exactly that system for code. Git tracks changes to your files, and GitHub stores those files online so you can share and collaborate with others.
In 2026, Git and GitHub are essential tools for developers, writers, designers, and anyone who works on digital projects. This beginner-friendly guide will teach you everything you need to know to get started.
What are Git and GitHub?
The Simple Analogy
It helps to think of Git and GitHub through everyday concepts:
- Git is like a Time Machine: It tracks every single change you make, lets you revert to any previous version, and works entirely locally on your computer.
- GitHub is like a Cloud Storage Service: It stores your Git history online, allows you to share it with others, enables seamless collaboration, and acts effectively as a “Dropbox for code”.
Git vs GitHub
| Feature | Git (The Tool) | GitHub (The Website) |
|---|---|---|
| Location | Installed on your computer | A website you visit |
| Function | Tracks changes locally | Stores code online |
| Connectivity | Works completely offline | Requires an internet connection |
| Cost | Free and open-source | Free tiers with paid professional plans |
| Interface | Primarily a command-line tool | A visual web-based interface |
Think of it this way: Git is like a camera taking continuous photos of your work, while GitHub is the online photo album where you store and share those photos.
Why Use Git and GitHub?
Benefits for Beginners
- ✅ Version Control Never lose your work again. You can go back to any previous version and easily see exactly what changed, when it changed, and who changed it.
- ✅ Reliable Backup Your code is stored securely online. You can access it from anywhere, eliminating the dreaded “my file got deleted” panic.
- ✅ Seamless Collaboration Work with others simultaneously. You can see who changed what and merge overlapping changes without destroying each other’s work.
- ✅ Professional Portfolio Showcase your work to potential employers, build your public coding portfolio, and contribute to open-source projects.
Getting Started
Step 1: Install Git
On Windows:
- Go to
git-scm.com - Download the Windows installer
- Run the installer using default settings
- Open the Git Bash terminal
- Check the installation by running:
git --version
On Mac:
# Option 1: Install with Homebrew
brew install git
# Option 2: Use Xcode Command Line Tools
xcode-select --install
# Check if it's installed:
git --version
On Linux (Ubuntu/Debian):
sudo apt update
sudo apt install git -y
# Check if it's installed:
git --version
Step 2: Set Up Your Identity
Tell Git who you are. These details will be attached to every commit you make.
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
# Verify your settings
git config --list
Step 3: Create a GitHub Account
- Go to
github.com - Click “Sign up”
- Enter your email and create a password
- Choose a unique username
- Verify your email address
- Choose the Free plan (it’s perfect for beginners)
Your username will form your profile URL: https://github.com/your-username
Basic Git Concepts
The Three States of Git
Understanding how files move through Git is the key to mastering it:
- Working Directory (Your Files): The files you’re currently editing. They are changed but not yet saved to Git.
→ run
git addto move to the Staging Area - Staging Area (Ready to Save): Files you’ve marked and prepared for your next save. They are ready for a snapshot.
→ run
git committo move to the Local Repository - Local Repository (Saved): The permanent database where Git stores your saved versions locally. You can revert to these versions anytime.
→ run
git pushto move to the Remote Repository - Remote Repository (GitHub): Your code is now stored online and can be shared with others.
The Basic Git Workflow
The daily routine of a developer looks exactly like this:
- Edit files (make your coding changes)
- Run
git status(review what changed) - Run
git add .(stage your changes) - Run
git commit -m "message"(save your changes permanently) - Run
git push(upload everything to GitHub)
Essential Git Commands
1. git init - Start a Repository
Think of this as turning a normal folder into a Git-tracked project folder.
mkdir my-first-project
cd my-first-project
# Initialize Git
git init
2. git status - Check What’s Happening
This is your most-used command. It tells you what branch you’re on, what files changed, what’s staged, and what’s untracked.
git status
3. git add - Stage Changes
Tell Git which modified files you want to include in the next save.
# Add a specific file
git add index.html
# Add all files in the current directory
git add .
4. git commit - Save Changes
Take a permanent snapshot of your staged changes. Always write clear, descriptive messages!
git commit -m "Add responsive navigation bar styling"
[!TIP] Good Commit Messages: “Add login page”, “Fix broken navigation”, “Update CSS styles”. Bad Commit Messages: “Updates”, “Fix stuff”, “Changes”, “asdf”.
5. git log - View History
See all your past commits in chronological order.
# View full history
git log
# View compact history
git log --oneline
6. git diff - See Changes
Compare what has changed in your files before you stage them.
# See unstaged changes
git diff
# Compare two commits
git diff commit_hash_1 commit_hash_2
7. git branch - Manage Branches
Branches let you work on different features safely without affecting the main codebase.
# Create and switch to a new branch
git checkout -b new-feature
# Switch back to main
git checkout main
8. git merge - Combine Changes
Bring completed work from a feature branch into your main branch.
# Switch to the branch you want to merge INTO
git checkout main
# Merge the feature branch
git merge new-feature
9. git remote - Connect to GitHub
Link your local project folder to an empty GitHub repository.
git remote add origin https://github.com/username/repo-name.git
10. git push - Upload to GitHub
Send your saved local commits to the remote GitHub server.
# First push (sets the upstream link)
git push -u origin main
# Subsequent pushes
git push
11. git pull - Download from GitHub
Fetch and merge the latest changes from GitHub to your local machine.
git pull origin main
12. git clone - Copy a Repository
Download an existing repository from GitHub to your computer.
git clone https://github.com/username/repo-name.git
Working with GitHub
Creating a Repository on GitHub
- Log into GitHub.
- Click the ”+” icon in the top right corner.
- Select “New repository”.
- Choose a repository name (e.g.,
my-first-project). - Add an optional description.
- Choose between Public (anyone can see) or Private.
- Do NOT initialize with a README if you are pushing an existing local project. DO initialize with a README if you are starting completely fresh.
- Click “Create repository” and follow the provided setup commands.
GitHub Authentication (Tokens)
GitHub no longer accepts account passwords for terminal authentication. You must use a Personal Access Token:
- Go to GitHub Settings → Developer settings.
- Select Personal access tokens → Tokens (classic).
- Click Generate new token.
- Select the
reposcope. - Generate the token and copy it immediately (you won’t be able to see it again).
- Paste this token as your password when your terminal prompts you to log in during a
git push.
Common Git Workflows
Workflow 1: The Personal Project
For simple solo projects, the workflow is incredibly straightforward:
- Make changes to your code files.
- Run
git add .to stage everything. - Run
git commit -m "Description of your changes"to save. - Run
git pushto back it up to GitHub.
Workflow 2: Feature Development
When building a new feature or working on a team, you should isolate your work:
- Run
git checkout -b new-feature-nameto create an isolated branch. - Make your code changes.
- Run
git add .andgit commit -m "Add new feature". - Run
git push origin new-feature-nameto push the branch to GitHub. - Create a Pull Request (PR) on GitHub to propose your changes.
- Once reviewed and merged, switch back locally using
git checkout main. - Update your local main branch by running
git pull.
Resolving Conflicts
Conflicts happen when two people edit the exact same line of code in the same file. Git doesn’t know which version is the “correct” one, so it pauses the merge and asks you to decide.
When you open a conflicted file, Git adds special markers:
<<<<<<< HEAD
console.log("Hello from the main branch!");
=======
console.log("Greetings from the feature branch!");
>>>>>>> feature-branch
How to resolve it:
- Manually edit the file to keep the correct code.
- Delete the Git markers (
<<<<<<<,=======,>>>>>>>). - Save the file.
- Run
git add filename. - Run
git commit -m "Resolve merge conflict". - Run
git push.
Quick Troubleshooting
- Problem:
"Permission denied" when pushingSolution: Ensure you are using a Personal Access Token or properly configured SSH key, not your account password. - Problem:
"No remote repository"Solution: You haven’t linked GitHub yet. Rungit remote add origin [URL]. - Problem:
"Your branch is behind"or"Failed to push"Solution: Someone else pushed changes. Rungit pullfirst, then try pushing again. - Problem:
"Unstaged changes"Solution: You have modified files that haven’t been committed. Rungit add .andgit committo save them.
Conclusion
Git and GitHub are essential tools for modern development. They protect your work, enable collaboration, and showcase your skills to the world.
Your Action Plan:
- Install Git and create a GitHub account.
- Initialize your first local repository.
- Practice the basic workflow:
add,commit,push. - Try branching and merging.
- Explore GitHub features like Issues, Pull Requests, and READMEs.
Ready to level up your development skills? Explore our Complete Developer Tools Guide for more essential resources.
Discussion
Loading comments...