DEV Community

Cover image for Git 101: Your Friendly Guide to Version Control
Jeffrey Njoroge
Jeffrey Njoroge

Posted on

Git 101: Your Friendly Guide to Version Control

What is Version Control Anyway?
Imagine you're writing an important document. You save version after version: essay.doc, essay_final.doc, essay_really_final.doc, essay_NO_REALLY_FINAL_v2.doc. Sound familiar? Version control is like a time machine for your code that saves you from this chaos. Git is simply a tool that manages these versions for you.

The Git Mindset: Your Project's Safety Net
Git creates a safety net for your projects by tracking every change. Made a change that broke everything? No problem—jump back to when it worked. Want to try a crazy idea? Create a separate "branch" to experiment without affecting the stable version.

Getting Started: Your First Repository
A repository (or "repo") is just a fancy word for a project folder that Git is tracking.

The Three Stages of Git

Think of Git having three areas:

  1. Working Directory: Your actual file
  2. Staging Area: A "preview" of what you're about to save
  3. Repository: Where Git permanently stores your changes

Tracking Changes: The Basic Workflow

Step 1: Check Your Status
Always know what's happening:

This shows what files are modified, staged, or untracked.

Step 2: Add Changes to Staging

Step 3: Commit Your Changes
A commit is a saved snapshot with a message describing what changed:

Pro tip: Write clear commit messages! Future you will thank past you.

Step 4: View Your History

This shows your commit history - your project's timeline.

Working with Remote Repositories (GitHub/GitLab)

Pushing Your Code

Pushing means uploading your commits to a remote server (like GitHub):

Pulling Changes

Pulling downloads changes from the remote server to your computer:

Always pull before you start working to get the latest changes!

Best Practices for Beginners

  1. Commit Often: Small, frequent commits are better than huge ones
  2. Write Good Messages: Use the present tense ("Add feature" not "Added feature")
  3. Pull Before You Push: Avoid merge conflicts
  4. Use Branches: Keep your main branch stable
  5. Don't Git Push --force: Unless you really know what you're doing

Your First Project Walkthrough
Here's what a typical workflow looks like:

Why Bother Learning Git?

  • Collaboration: Multiple people can work on the same project
  • Backup: Your code lives on GitHub's servers
  • Experimentation: Try ideas safely in branches
  • Portfolio: GitHub becomes your coding resume

Next Steps

Once you're comfortable with these basics, explore:

  • Branching and merging
  • Handling merge conflicts
  • Git ignore files (.gitignore)
  • Pull requests on GitHub

Remember: Every Git expert was once a beginner who accidentally deleted something. Don't be afraid to make mistakes—that's how you learn! The most important command to know is git status. When in doubt, check your status.

Top comments (1)

Collapse
 
avedi profile image
Owen Avedi

Insightful