Git Started: A Beginner’s Guide to Essential Git Commands

Feeling overwhelmed by version control? You aren’t alone. Whether you’re a student, a budding developer, or just curious about how projects are managed, Git is the industry standard for tracking changes in source code.

In this post, we’ll break down the most essential commands you need to survive (and thrive) in your first repository.

What is Git?

Git is a version control system that allows you to save “snapshots” of your project. If you make a mistake, you can simply roll back to a previous version. It’s like having a “Save Game” feature for your code.

1. Setting the Foundation

Before you start coding, you need to tell Git who you are. This information is attached to your “commits” (saves).

  • Set your username: git config --global user.name "Your Name"
  • Set your email: git config --global user.email "youremail@example.com"

2. Starting a Repository

You can either start a brand new project or download one that already exists.

  • Initialize a new local repo: git init (Use this inside your project folder to start tracking it.)
  • Clone an existing repo: git clone <url> (Copies a project from a site like GitHub to your computer.)

3. The “Big Three” Workflow

Most of your time in Git will be spent in a cycle: Add, Commit, and Push.

Step 1: Add (The Staging Area)

When you change a file, Git notices, but it doesn’t save it yet. You need to “stage” the files you want to include in your next save.

  • git add index.html (Stages a specific file)
  • git add . (Stages all changed files)

Step 2: Commit (The Snapshot)

This permanently saves your staged changes to the local history. Always include a clear message!

  • git commit -m "Fix the navigation bar bug"

Step 3: Push (Sharing)

If you are working with a remote server (like GitHub), this sends your local saves to the cloud.

  • git push origin main

4. Checking Your Status

If you ever feel lost and don’t know what has been saved or changed, use these:

CommandPurpose
git statusShows which files are staged, unstaged, or untracked.
git logShows a history of all your past commits.
git diffShows the specific line-by-line changes in your files.

Export to Sheets

5. Branching: Experiment Safely

Branches allow you to work on new features without breaking the “Main” working version of your code.

  • Create a new branch: git branch feature-name
  • Switch to that branch: git checkout feature-name
  • Merge changes back to main: git merge feature-name (Run this while you are on the main branch).

Summary Checklist

  1. git init to start.
  2. git add . to prepare.
  3. git commit -m "message" to save.
  4. git push to share.

Leave a Reply

Your email address will not be published. Required fields are marked *