Git for beginners
What is GIT?
Git is a distributed version control system - a fancy term for a time machine for your code. Imagine you're writing a book. Without Git, you would probably have files like my_book_v1.doc, my_book_final.doc, and my_book_final_v2.doc cluttering your folder. With Git, you maintain one clean file while the system automatically preserves every version, every chapter draft, and every edit, letting you travel back to any point in your project's history with a simple command.
Even better, Git does this so efficiently that you can work simultaneously with teammates without overwriting each other's changes, merge different versions seamlessly, and always have a complete safety net for your creative work.
Why is Git used?
Track Changes: See exactly what changed, when, and why
Collaborate Smoothly: Multiple developers can work on different features simultaneously
Experiment Safely: Try new ideas without breaking your working code
Rollback Easily: Revert to previous versions when things go wrong
Understand Your Codebase: See the evolution of your project through detailed history
Git Basics and Core Terminologies
Before we dive into commands, let's understand some key concepts:
Repository: The project folder where Git tracks all changes. It contains your code files and Git's history database.
Commit: A snapshot of your project at a specific point in time. Each commit has a unique ID, author, timestamp, and message explaining the changes.
Staging Area: A preparatory area where you select which changes will be included in your next commit.
Branch: A separate timeline for your project. The default branch is usually called
mainormaster. Branches allow you to work on features independently.HEAD: A pointer to the latest commit in your current branch
Remote: A hosted version of your repository, typically on services like GitHub, GitLab, or Bitbucket.
Common Git Commands
Getting started
git initInitializes a new Git repository in your current directory. This creates a hidden
.gitfolder that tracks everything.Checking Your Status
git statusShows what files have changed and what's staged for commit. It's your project's dashboard.
The Core Workflow Commands
- Stage Your Changes
git add . # Add all changes
git add index.html style.css # Add specific files
This selects which modifications you want to include in your next snapshot.
- Create a Snapshot
git commit -m "Add login page"
Creates a permanent record of your staged changes with a descriptive message.
- Share Your Work
git push origin main
Sends your committed changes to a shared repository (like GitHub or GitLab).
Viewing History
git log git log --oneline # Compact viewShows your commit history.
A beginner’s workflow for creating a simple website along with git:
# 1. Create project and initialize Git
mkdir my-website
cd my-website
git init
# 2. Create your first files
echo "# Welcome to My Site" > README.md
echo "<!DOCTYPE html><html><body><h1>Hello!</h1></body></html>" > index.html
# 3. See what Git sees
git status
# 4. Stage your files
git add .
# 5. Create your first commit
git commit -m "Initial commit with homepage and readme"
# 6. Connect to GitHub (create repo first on GitHub)
git remote add origin https://github.com/rohan9896/my-website.git
# 7. Push to the cloud
git push -u origin main
Wrapping Up
Git transforms how we work with code, turning chaos into organized history. Start with these basics, practice the add-commit-push workflow, and soon you'll be navigating your project's timeline with confidence.
Enjoyed this guide? Let's connect!
🐦 Twitter/X: @rohan_gupta96
💼 LinkedIn: https://www.linkedin.com/in/rohangupta9896
🐙 GitHub: https://github.com/rohan9896