DEV Community

Akanksha Sharma
Akanksha Sharma

Posted on

Git Without the Confusion: The Commands You’ll Actually Use

If you're new to Git, you've probably seen a command like this:

git checkout -b feature/login
Enter fullscreen mode Exit fullscreen mode

…and thought:

“Okay… but what exactly am I supposed to remember?”

Git has a lot of commands.

The good news?

You don't need to memorize all of them.

For everyday development there's a small set of commands you'll use again and again.

So instead of throwing 50+ commands at you here's a practical Git cheat sheet for beginners that you can bookmark and come back to whenever Git decides to confuse you.


⚡ The Quick Git Cheat Sheet

Before getting into the details, here's the short version:

I want to... Command
Set my Git name git config
Start Git in a project git init
Download a repository git clone
See what's changed git status
Review my changes git diff
Stage changes git add
Save a checkpoint git commit
View commit history git log
Create a branch git branch
Switch branches git switch
Merge a branch git merge
Upload commits git push
Get remote changes git pull
Check remote changes without integrating git fetch
Temporarily save changes git stash
Safely undo a commit git revert

You don't need to memorize this table.

*Bookmark it. That's literally what it's here for. *


1. Configure Git

Before using Git, tell it who you are.

• Set Your Name

git config --global user.name "Your Name"
Enter fullscreen mode Exit fullscreen mode

Tells Git which name to associate with your commits.

• Set Your Email

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

Sets the email associated with your commits.

• Check Your Configuration

git config --list
Enter fullscreen mode Exit fullscreen mode

Useful when you want to verify your Git settings.

Think of this as telling Git:

“Hey, these commits belong to me.”


2. Start Working With a Repository

There are two common ways to start working with Git.

• Create a New Repository

git init
Enter fullscreen mode Exit fullscreen mode

Initializes Git inside your current project folder.

Use this when you already have a project on your computer and want Git to start tracking it.

• Clone an Existing Repository

git clone <repo_url>
Enter fullscreen mode Exit fullscreen mode

Downloads an existing repository to your computer.

Use this when a project already exists on a remote platform such as GitHub and you want a local copy.

• Easy way to remember:

git init → start Git here

git clone → bring an existing repository here


3. Track and Save Your Changes

This is where you'll probably spend most of your time.

Imagine this:

You changed three files and now have absolutely no idea what Git thinks happened.

Start with:

• Check What Changed

git status
Enter fullscreen mode Exit fullscreen mode

Shows modified, staged and untracked files.

When you're confused about what's happening in your repository:

Run git status.

Seriously.

• Review Your Changes

git diff
Enter fullscreen mode Exit fullscreen mode

Shows changes that haven't been staged yet.

It's useful when you want to review your work before staging it.

Think:

“What exactly did I change?”

→ git diff

• Stage a Specific File

git add <file>
Enter fullscreen mode Exit fullscreen mode

Example:

git add index.html
Enter fullscreen mode Exit fullscreen mode

This tells Git:

“Include this file's changes in my next commit.”

• Stage Everything

git add .
Enter fullscreen mode Exit fullscreen mode

Stages changes under the current directory and its subdirectories.

It's convenient when you're sure you want to include those changes.

Still, it's a good habit to check:

git status
Enter fullscreen mode Exit fullscreen mode

before committing.

If you only want to stage a specific file:

git add <file>
Enter fullscreen mode Exit fullscreen mode

• Create a Commit

git commit -m "Add login form"
Enter fullscreen mode Exit fullscreen mode

A commit is basically a checkpoint for your project.

Instead of:

git commit -m "changes"
Enter fullscreen mode Exit fullscreen mode

prefer something descriptive:

git commit -m "Fix navbar responsiveness"
Enter fullscreen mode Exit fullscreen mode

Good commit messages make your project history much easier to understand.

Think:

Commit = save a checkpoint of your staged changes.

• See Your Commit History

git log
Enter fullscreen mode Exit fullscreen mode

Shows previous commits along with information such as the author, date and commit message.

Want a shorter version?

git log --oneline
Enter fullscreen mode Exit fullscreen mode

This gives you a compact view of your commit history.


4. Work With Branches

Branches let you work on features, experiments or fixes separately from your main branch.

For example:

main
 │
 ├── feature/navbar
 ├── feature/login
 └── fix/mobile-layout
Enter fullscreen mode Exit fullscreen mode

Instead of experimenting directly on main, you can create a separate branch for your work.

• See Your Branches

git branch
Enter fullscreen mode Exit fullscreen mode

Lists your local branches.

• Create a Branch

git branch <name>
Enter fullscreen mode Exit fullscreen mode

Example:

git branch feature/navbar
Enter fullscreen mode Exit fullscreen mode

Creates a new branch but does not switch you to it.

• Switch Branches

Modern Git provides git switch specifically for changing branches:

git switch <branch>
Enter fullscreen mode Exit fullscreen mode

Example:

git switch feature/navbar
Enter fullscreen mode Exit fullscreen mode

You may also see this older, still-common command:

git checkout feature/navbar
Enter fullscreen mode Exit fullscreen mode

You don't necessarily need to use checkout for everyday branch switching but you should recognize it because you'll encounter it in older tutorials and projects.

• Create and Switch to a Branch

With modern Git:

git switch -c <branch>
Enter fullscreen mode Exit fullscreen mode

Example:

git switch -c feature/navbar
Enter fullscreen mode Exit fullscreen mode

This does two things:

Create branch → Switch to branch

You may also see:

git checkout -b feature/navbar
Enter fullscreen mode Exit fullscreen mode

Both patterns are worth recognizing.

• Merge a Branch

Suppose you're currently on main and want to bring changes from feature/navbar into it:

git merge feature/navbar
Enter fullscreen mode Exit fullscreen mode

Git combines the changes from the specified branch into your current branch.

The important part:

Git merges into the branch you're currently on.

So if you're on main:

git merge feature/navbar
Enter fullscreen mode Exit fullscreen mode

means:

“Bring feature/navbar into main.”


5. Work With Remote Repositories

Your local Git repository and a remote repository such as GitHub are separate.

These commands help you synchronize them.

• See Connected Remotes

git remote -v
Enter fullscreen mode Exit fullscreen mode

Shows the remote repositories connected to your project.

• Add a Remote

git remote add origin <url>
Enter fullscreen mode Exit fullscreen mode

origin is simply the conventional name for the remote repository.

• Push Your Commits

git push origin <branch>
Enter fullscreen mode Exit fullscreen mode

Example:

git push origin main
Enter fullscreen mode Exit fullscreen mode

Uploads your local commits to the remote repository.

Think:

push → send my commits to the remote

• Pull Remote Changes

git pull
Enter fullscreen mode Exit fullscreen mode

Gets changes from the remote repository and integrates them into your current branch.

Depending on your Git configuration that integration may involve merging or rebasing.

For beginners, remember:

pull → get remote changes + integrate them

• Fetch Remote Changes

git fetch
Enter fullscreen mode Exit fullscreen mode

Downloads information about remote changes without automatically integrating them into your current branch.

A simple way to remember the difference:

fetch = get the information

pull = get + integrate


6. Undo and Manage Changes

This is where Git can start feeling a little scary.

But you don't need to memorize every recovery command.

Here are some common situations.

• Unstage a File

If you've staged a file but want to remove it from the staging area while keeping your changes:

git restore --staged <file>
Enter fullscreen mode Exit fullscreen mode

Example:

git restore --staged index.html
Enter fullscreen mode Exit fullscreen mode

Think:

“Keep my changes, but take this file out of staging.”

You may also see:

git reset <file>
Enter fullscreen mode Exit fullscreen mode

in older tutorials and workflows.

• Safely Undo a Commit

git revert <commit_id>
Enter fullscreen mode Exit fullscreen mode

Creates a new commit that reverses the changes introduced by an earlier commit.

This is useful when you want to undo a committed change while keeping the existing history intact.

• Temporarily Save Your Changes

git stash
Enter fullscreen mode Exit fullscreen mode

Imagine you're working on something unfinished and suddenly need to switch branches.

You don't want to commit the unfinished work.

That's where stash can help.

git stash
Enter fullscreen mode Exit fullscreen mode

Temporarily stores your local changes.

• Bring Stashed Changes Back

git stash pop
Enter fullscreen mode Exit fullscreen mode

Restores the most recently stashed changes and removes that stash entry if the changes are applied successfully.

Easy way to remember:

stash → put it away

stash pop → bring it back

• Remove a File

git rm <file>
Enter fullscreen mode Exit fullscreen mode

Removes the file and stages that removal.

Example:

git rm old-file.js
Enter fullscreen mode Exit fullscreen mode

• Rename or Move a File

git mv <old> <new>
Enter fullscreen mode Exit fullscreen mode

Example:

git mv old.js new.js
Enter fullscreen mode Exit fullscreen mode

Renames or moves a file while letting Git track the change.


7. The Git Workflow You'll Actually Use

For many everyday tasks, the workflow looks like this:

Make changes
     ↓
git status
     ↓
git diff
     ↓
git add .
     ↓
git commit -m "Describe your changes"
     ↓
git push
Enter fullscreen mode Exit fullscreen mode

Think of it as:

Change → Check → Review → Stage → Commit → Push

That's the basic rhythm you'll repeat constantly while working with Git.

Once you understand this flow, individual commands become much easier to remember.


8. What to Remember First

If you're completely new to Git, don't try to memorize everything at once.

Start with these:

git status
git diff
git add
git commit
git log
git switch
git pull
git push
Enter fullscreen mode Exit fullscreen mode

Then gradually add:

git init
git clone
git branch
git merge
git fetch
git stash
git revert
git restore
Enter fullscreen mode Exit fullscreen mode

You don't need to know Git perfectly before using Git.

Use the commands. Understand what they do. Look them up when you forget.

Eventually, they become second nature.

And when you forget one?

That's what cheat sheets are for.


Bookmark This

Git isn't about memorizing hundreds of commands.

It's about understanding the workflow:

Change
  ↓
Check
  ↓
Review
  ↓
Stage
  ↓
Commit
  ↓
Push
Enter fullscreen mode Exit fullscreen mode

Once that workflow makes sense, Git becomes much less intimidating.

You don't need to remember every command today.

You just need to know what you're trying to do and which command helps you do it.

And yes...

you'll probably still Google git stash six months from now.

Save this for the next time Git decides to humble you.

And tell me:

Which Git command took you the longest to understand? 👇

Top comments (0)