Git & GitHub
Complete Reference Guide
Everything you need to master version control — from your very first commit to advanced team workflows. Designed for beginners looking to learn and professionals who need a quick reference.
Getting Started
Brand new to Git? Start here. These commands will help you install, configure, and understand the basics of version control.
What is Git?
Git is the world's most popular version control system. It lets you track every change you make to your code, collaborate with other developers, and safely experiment with new ideas without breaking your project. Think of it as an "undo button" for your entire codebase.
First-Time Configuration
Before you start using Git, you need to tell it who you are. Your name and email will be attached to every commit (save point) you create. This is how your teammates will know who made each change.
Creating Projects
Every project starts somewhere. Learn how to create a brand new repository or download an existing one.
Initialize a New Repository
When you start a new project from scratch, you need to initialize a Git repository. This creates a hidden .git folder that tracks all your changes from this point forward.
Clone an Existing Repository
If a project already exists on GitHub (or another remote server), you can download the entire project — including its full history — using the clone command.
Day-to-Day Workflow
These are the commands you will type every single day. Master them and Git becomes effortless.
Checking the Status
Before you do anything in Git, it's a good habit to check your status. This tells you which files have been modified, which are staged (ready to commit), and which are untracked (new files Git doesn't know about yet).
Staging Changes
Before committing, you need to 'stage' your changes. Staging means selecting exactly which changes you want to include in your next save point. This gives you fine-grained control over your project history.
Committing Changes
A commit is a permanent save point in your project's history. Every commit has a unique ID and a message describing what changed. Good commit messages make your project's history easy to understand.
Viewing History
Your project's history is a powerful record of every change ever made. You can browse it, search it, and even travel back in time to any point.
Branching & Merging
Branches let you work on new features, bug fixes, or experiments in isolation — without affecting the main codebase.
Working with Branches
A branch is like a parallel universe for your code. You can create a branch, make changes, and merge them back when you're ready. The main branch stays safe while you experiment freely.
Merging Branches
Once your work on a branch is complete, you merge it back into the main branch. Git intelligently combines the changes. If two people edited the same line, Git will ask you to resolve the conflict manually.
Remote & Collaboration
Git becomes truly powerful when you connect it to a remote server like GitHub. These commands let you share your work and collaborate with others.
Connecting to Remote
A 'remote' is a version of your project hosted on the internet (like GitHub). When you clone a repository, the remote is set up automatically. For projects you initialized locally, you need to add it manually.
Pushing & Pulling
Push sends your local commits to the remote server so others can see your work. Pull downloads the latest changes from the remote and merges them into your local branch.
Undoing Mistakes
Made a mistake? Don't panic. Git has powerful tools to undo almost anything, from a simple typo to an entire commit.
Unstaging & Discarding
If you accidentally staged a file or want to throw away recent changes, these commands can help you go back without losing your commit history.
Reverting & Resetting Commits
If you need to undo an entire commit, you have two options: revert (safe — creates a new commit that undoes the changes) or reset (destructive — rewrites history).
Stashing
Need to quickly switch branches but have uncommitted work? Stash lets you save your current changes temporarily and come back to them later.
Using the Stash
The stash is like a clipboard for your code. It saves your current work-in-progress and gives you a clean working directory. When you're ready, you can pop the changes right back.
Advanced Techniques
Ready to level up? These advanced commands give you surgical precision over your commit history and workflow.
Interactive Rebase
Rebase lets you rewrite your commit history. You can squash multiple messy commits into one clean commit, reorder them, rename them, or even delete specific commits entirely.
Cherry-Pick
Cherry-pick lets you copy a specific commit from one branch and apply it to another. This is useful when you only need one particular change, not an entire branch merge.
Tagging Releases
Tags mark important points in your project's history, like version releases. Unlike branches, tags don't change — they're permanent bookmarks.
Inspection & Debugging
When things go wrong, these commands help you investigate, compare, and find exactly where a bug was introduced.
Comparing Changes
The diff command shows you exactly what has changed, line by line. This is essential for code reviews and understanding what happened between two points in your history.
Blame & Bisect
Who changed this line? When was a bug introduced? Git's blame and bisect tools help you answer these detective questions.
Cleanup & Maintenance
Keep your repository clean and organized with these housekeeping commands.
Cleaning Up
Over time, your working directory can accumulate untracked files (build artifacts, temp files, etc.). The clean command helps you remove them.
Using .gitignore
The .gitignore file tells Git which files and folders to completely ignore. This is essential for keeping sensitive data, build artifacts, and dependencies out of your repository.