8 Daily Git Commands You Need: Switch, Checkout, and Pull Rebase Explained

Fred· AI Engineer & Developer Educator4 min read

Git is powerful, but it has a reputation for being complicated. It includes hundreds of commands and flags, yet most developers only rely on a small set of them every day. If you learn the eight commands in this guide, you can work confidently in almost any Git project without needing to memorize the rest.

The 8 Essential Commands

1. git status

Use this to check the state of your workspace. It shows which files have changed, which files are staged, which branch you are on, and whether your branch is ahead or behind the remote. This command is your main dashboard.

git status

2. git add .

This stages your changes so they are ready to be committed. The dot means "add everything that changed". You can also stage individual files if you prefer to be more selective.

git add .
# Or stage specific files:
git add src/index.js

3. git commit -m ""

A commit creates a snapshot of your work. The message inside the quotes should describe why the change was made. Good commit messages save time later when reviewing history or debugging issues.

git commit -m "Add user authentication flow"

4. git pull --rebase

This updates your local branch with the latest changes from the remote. The --rebase flag keeps your commit history clean by replaying your commits on top of the newest upstream commits. This avoids unnecessary merge commits and reduces conflict noise.

git pull --rebase

Why rebase? Without it, you get merge commits every time you pull, cluttering your history with "Merge branch 'main' into main" messages.

5. git push

This uploads your commits to GitHub, GitLab, or any other remote. Pushing saves your work to the server, backs it up, and makes it available for pull requests and team collaboration.

git push
# First push on a new branch:
git push -u origin feature/my-branch

6. git switch <branch>

This is the modern way to switch to another branch. It is simple, clear, and cannot accidentally modify your files.

git switch main
git switch feature/login

If the branch does not exist yet, create it with:

git switch -c new-branch

7. git merge <branch>

This merges the specified branch into the branch you are currently on. The correct order is to switch into the branch you want to update first, then merge another branch into it.

git switch main
git merge feature/login

8. git checkout -

This returns you to the previous branch along with its working state. It is an extremely useful shortcut and one of the only modern uses of git checkout that is still recommended.

git checkout -
# Equivalent to "cd -" for branches

Quick Reference

Command What It Does
git status Show workspace state
git add . Stage all changes
git commit -m "msg" Create a commit
git pull --rebase Update from remote (clean history)
git push Upload commits
git switch <branch> Change branches
git merge <branch> Merge branch into current
git checkout - Return to previous branch

Modern Git: Switch vs Checkout

Since Git 2.23, things have become even simpler. Git introduced two new commands, git switch and git restore, to separate branch switching from file restoration. This change makes the intent of each command clear, especially for new developers. The old git checkout command was overloaded and tried to do too many unrelated things.

Here is the simple rule set for modern Git usage:

Command Purpose
git switch Changes branches
git checkout - Returns to previous branch
git checkout Should NOT be used for switching branches (except the dash shortcut)

Wrapping Up

If you master these eight commands, you will be effective in almost every daily Git workflow without needing any advanced knowledge. The key insight is using git switch for branches and reserving git checkout only for the dash shortcut.

For everything else—rebasing, cherry-picking, bisecting—you can look it up when you need it. These eight commands cover 95% of what you'll do every day.

Fred

Fred

AUTHOR

Full-stack developer with 10+ years building production applications. I write about cloud deployment, DevOps, and modern web development from real-world experience.