Essential Git Commands Every Developer Should Master

Because clean version control is a superpower

If you’re a developer, Git is not optional — it’s survival.
Whether you’re building Salesforce solutions, web apps, or enterprise systems, Git helps you track changes, collaborate confidently, and recover from mistakes without panic.

In this blog, we’ll walk through practical Git commands every developer actually uses, explained in a simple, hands-on way. No theory overload. No boring definitions. Just real-world Git.


Why Version Control Matters (More Than You Think)

Version control allows you to:

  • Save multiple versions of your code

  • Compare changes over time

  • Roll back mistakes safely

  • Work in parallel with teams without overwriting each other

Git does all of this efficiently — and once you understand the basics, it becomes second nature.


What Exactly Is Git?

Git is a distributed version control system.
Unlike traditional systems that store only changes, Git stores snapshots of your entire project at each stage.

This means:

  • Faster operations

  • Reliable history

  • Full control over your code timeline

You can commit changes, experiment freely, and always return to a stable version if something breaks.


Git vs GitHub (Clearing the Confusion)

Many beginners mix these two — so let’s simplify.

Git
  • Runs on your local machine

  • Tracks code changes

  • Open-source and free

  • Works offline

GitHub
  • Cloud platform that hosts Git repositories

  • Enables team collaboration

  • Provides UI, pull requests, reviews, and CI integrations

  • Owned by Microsoft

👉 Think of Git as the engine, and GitHub as the garage where everyone works together.


Common Git Terms You Should Know

  • Repository (Repo): Your project’s codebase

  • Branch: A separate line of development

  • Commit: A saved snapshot of changes

  • Push: Send local commits to GitHub

  • Pull: Get latest changes from GitHub

  • Merge: Combine branches

  • Tag: A label for a specific release/version


Installing Git on Your System

Before anything else, install Git on your machine.

Download Git from the official site:
👉 https://git-scm.com/download/win

Once installed, you’ll get access to Git Bash, which we’ll use for all commands.


Git Commands Every Developer Should Know 🔥

Let’s break this into three parts:

  1. Local setup

  2. Working with local repositories

  3. Working with remote repositories (GitHub)


1️⃣ Local Environment Setup

Git Configuration (One-Time Setup)

Before committing anything, tell Git who you are.

git config --global user.name "Apex Hours"
git config --global user.email "amit.salesforce21@gmail.com"

This information appears in your commit history.


2️⃣ Working with a Local Git Project

Initialize a Repository

Create a folder → right-click → Git Bash Here

git init

This turns your folder into a Git-tracked repository.


Check File Status

git status

Shows:

  • Untracked files

  • Staged files

  • Changes ready to commit

This is one of the most-used Git commands — trust me.


Stage Files for Commit

Add a single file:

git add logfile.txt

Add all .txt files:

git add *.txt

Add everything:

git add .

Staging means: “This is ready to be committed.”


Remove Files from Staging

If you added something by mistake:

git rm --cached filename

Other modern alternatives:

  • git reset HEAD filename

  • git restore --staged filename


Commit Your Changes

git commit -m "Initial commit"

Each commit should describe what changed and why.


The .gitignore File (Very Important)

.gitignore tells Git which files it should never track.

Common examples:

  • Logs

  • Environment files

  • Node modules

  • Build folders

Once listed here, Git ignores them permanently.


Create and Manage Branches

Create a branch:

git branch BugFix

Switch to it:

git checkout BugFix

Branches allow you to work safely without touching production code.


Merge Branches

If you’re on one branch and want changes from another:

git merge main

This combines work from both branches into one.


3️⃣ Working with Remote Repositories (GitHub)

Once local Git is clear, collaboration begins.


Add a Remote Repository

git remote add origin <repo-url>

Check connected remotes:

git remote

Push Code to GitHub

git push origin main

This uploads your local commits to GitHub.


Clone a Repository

To copy an existing repo to your system:

git clone <repo-url>

Perfect for onboarding new team members.


Fetch vs Pull (Important Difference)

Fetch:

git fetch origin

Downloads changes without modifying your local work.

Pull:

git pull origin

Fetches and merges changes immediately.


Additional Git Commands You’ll Love

View Commit History
git log
git log -10
Compare Changes
git diff commit1 commit2
Revert a Commit (Safe Undo)
git revert <commit-id>
Reset Local Changes
git reset --hard <commit-id>

⚠️ Use reset carefully — especially if code is already pushed.


Final Thoughts 💡

Git is not just a tool — it’s a developer’s safety net.

Once these commands become muscle memory:

  • You’ll code faster

  • Collaborate better

  • Fix mistakes confidently

  • Work like a professional developer

In upcoming blogs, we’ll connect Salesforce Org with VS Code using Git and Salesforce CLI, step by step.

Leave a Comment

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