DEV Community

Cover image for Git BEGINNER’S MANUAL
Cynthia Teigut
Cynthia Teigut

Posted on

Git BEGINNER’S MANUAL

If you’re just starting out with coding or working on projects with others, you’ve probably heard about Git.

Git is a tool that helps you keep track of your code, see what changes were made, and work with others without accidentally messing things up. Think of it like a magical notebook that remembers every change you make and lets you go back in time whenever you need.

This guide will walk you through the basics: tracking changes, pushing and pulling code, and understanding version control—all in plain English.

What is Version Control, Anyway?

Before Git, managing code changes was messy. If two people edited the same file, it could be a nightmare to combine their work. That’s where version control comes in.

Version control systems (like Git) keep a history of your project. You can:

  • See exactly what changed and when.
  • Revert back if something breaks.
  • Collaborate with others safely.

Basically, Git keeps your code organized and your sanity intact.

Git Basics: Key Terms You Should Know

Here are a few words you’ll see all the time in Git:

  • Repository (repo) – Your project folder tracked by Git. You can have one on your computer (local) or on GitHub (remote).
  • Commit – A snapshot of your code at a particular moment. Think of it like saving your game progress.
  • Branch – A parallel version of your project. You can experiment on a branch without affecting the main project.
  • Push – Send your local changes to the online repository.
  • Pull – Grab the latest changes from the online repository to your computer.

Step 1: Setting Up Git

Before you start using Git, you need to install it and tell it who you are:

  1. Install Git
    Download it from git-scm.com and follow the instructions for your computer.

  2. Set your name and email

   git config --global user.name "Your Name"
   git config --global user.email "you@example.com"
Enter fullscreen mode Exit fullscreen mode

This tells Git who made which changes.

Step 2: Starting a Git Repository

To start tracking your project:

cd path/to/your/project
git init
Enter fullscreen mode Exit fullscreen mode

This creates a hidden folder where Git keeps track of everything you do.

Step 3: Tracking Your Changes

Git keeps an eye on your files, but you have to tell it when you want to save a snapshot:

  1. Check what’s changed
   git status
Enter fullscreen mode Exit fullscreen mode
  1. Stage files – Choose which files you want to save:
   git add filename
Enter fullscreen mode Exit fullscreen mode

Or all files at once:

   git add .
Enter fullscreen mode Exit fullscreen mode
  1. Commit changes – Save a snapshot:
   git commit -m "A short description of what you changed"
Enter fullscreen mode Exit fullscreen mode

Think of staging as packing your bag and commit as taking a photo before sending it off.

Step 4: Working With a Remote Repository

If you’re collaborating, you’ll probably use a platform like GitHub. Here’s how:

  1. Connect your local repo to GitHub
   git remote add origin https://github.com/username/repo.git
Enter fullscreen mode Exit fullscreen mode
  1. Push your changes – Send your local commits to GitHub:
   git push origin main
Enter fullscreen mode Exit fullscreen mode
  1. Pull changes – Get the latest updates from GitHub:
   git pull origin main
Enter fullscreen mode Exit fullscreen mode

Always pull before pushing so you don’t overwrite someone else’s work.

Step 5: Viewing History and Differences

  • See all commits:
  git log
Enter fullscreen mode Exit fullscreen mode
  • See what changed in a file:
  git diff filename
Enter fullscreen mode Exit fullscreen mode

This is like checking your project’s “time machine” to see what was done and when.

Step 6: Branching (Optional, But Handy)

Branches let you try new ideas without messing up the main project:

  • Create a branch
  git branch new-feature
Enter fullscreen mode Exit fullscreen mode
  • Switch to that branch
  git checkout new-feature
Enter fullscreen mode Exit fullscreen mode
  • Merge back to main when ready
  git checkout main
  git merge new-feature
Enter fullscreen mode Exit fullscreen mode

Branches are like experimenting in a sandbox—you can play around safely!

Tips for Beginners

  1. Commit often. Small changes are easier to manage.
  2. Write meaningful commit messages. It helps you (and your teammates) understand your changes.
  3. Pull before pushing. Avoid conflicts!
  4. Use branches to try new things without breaking the main project.

Conclusion

Git might seem intimidating at first, but once you get the hang of it, it’s a lifesaver for developers. It helps you track your code, collaborate safely, and fix mistakes without panic.

Start small: make commits, push and pull, and explore branches. Soon, using Git will feel like second nature.

Top comments (0)