ToolPal
Terminal window showing git commands on a dark screen

Git Command Generator — Stop Googling the Same Commands Every Day

📷 Yancy Min on Unsplash / Pexels

Git Command Generator — Stop Googling the Same Commands Every Day

A practical guide to the git commands every developer actually uses, organized by what you are trying to do. Covers branching, undoing mistakes, working with remotes, stashing, and advanced tricks.

DBy Daniel ParkApril 22, 202612 min read

I used to have a browser tab permanently open to the git documentation. Not because I did not know git — I had been using it for years — but because I kept blanking on the exact syntax for things I only did occasionally. Was it git reset --soft or git reset --cached when I wanted to unstage but not lose changes? Did git stash apply remove the stash or leave it? Was the flag for setting upstream -u or --set-upstream?

Every developer I know has a version of this experience. Git is one of those tools where the daily-driver commands become reflex within weeks, but the medium-frequency commands — the ones you use every few days or once a week — never quite stick. You learn them, forget them, re-learn them, forget them again.

The Git Command Generator on ToolBox Hub exists for exactly those moments. Instead of tab-switching to documentation, you can filter by category, search by what you are trying to do, fill in a branch name or commit hash, and copy the complete command. No hunting, no wrong-flag debugging.

How the Tool Works

When you open the Git Command Generator, you see a search bar and a row of category buttons: Basic, Branching, Remote, Undo, Stash, and Advanced.

The command cards each show the command in a monospace code block, a plain-English description of what it does, and a copy button. For commands that need a parameter — a branch name, a file path, a commit hash — there is a text input below the card. Whatever you type gets substituted into the command template in real time, so the copy button always copies the ready-to-run version.

For example, if you click on the "Create and switch to new branch" card and type feature/payments in the branch name field, the command block instantly updates to git checkout -b feature/payments and that is what gets copied to your clipboard.

The search bar filters across both command names and descriptions, so you can type "undo" and see every relevant command, or type "stash" and see the full stash workflow together.

The Commands You Will Actually Use

Rather than going through all 40+ commands alphabetically, let me walk through the categories the way they come up in a real workday.

Setting Up and Daily Basics

The commands in the Basic category are the ones muscle memory takes over within your first month. git status is probably the most-run git command in existence — it tells you what is staged, what is not, and what is untracked. git add . stages everything in the current directory. git commit -m "message" creates a commit.

The two I see developers underuse in this category are git diff and git diff --staged. Running git diff before you add anything shows you precisely what changed in your working tree since the last commit. Running git diff --staged after adding shows what is actually going into your next commit. Getting into the habit of reviewing these before every commit catches a surprising number of debug logs, commented-out code blocks, and accidental file inclusions.

git log --oneline is another underrated daily tool. The default git log output is verbose to the point of being hard to skim. The --oneline version compresses each commit to a single line: the first 7 characters of the hash and the commit message subject. Much faster for finding the commit you are looking for.

Branching Strategy

The Branching category covers everything from creating branches to merging and tagging.

git checkout -b <branch> (or the newer git switch -c <branch>) is how most feature work starts. You name it, you switch to it, you build. When the work is done, you open a pull request or merge it back. Standard flow.

The commands people get fuzzy on are git merge versus git rebase. Both integrate changes from one branch into another, but they do it differently.

git merge creates a merge commit. Your branch history and the target branch history are both preserved, and the merge commit shows where they joined. If you look at a git graph, merge commits create a diamond shape. This is faithful to what actually happened — two parallel workstreams converged — and it is the safe default for team workflows.

git rebase takes your commits, rewinds the branch pointer to the target branch tip, and replays your commits on top. The result is a straight line of commits with no merge diamonds. The upside is readability — git log is easier to follow. The downside is that rebase rewrites commit hashes, which creates problems if anyone else has pulled those commits. The rule: rebase on personal or local branches, merge on shared ones.

git branch -d <branch> deletes a local branch after merging. Git is conservative here and will refuse to delete if the branch has unmerged commits. If you genuinely want to discard an unmerged branch, use -D (uppercase). The generator includes -d specifically because it is the safe version.

Working with Remotes

The Remote category covers the commands that touch the server.

git fetch origin is subtly different from git pull. Fetch only downloads new commits and branches from the remote — it does not touch your local branches at all. Pull is a fetch followed by a merge. I prefer to fetch first and look at what changed before merging, especially on active shared branches. It is a small habit that has saved me from surprise conflicts more than once.

git push -u origin <branch> is the first push for a new branch. The -u flag sets the upstream tracking relationship, so after this, git push and git pull with no arguments work automatically on that branch. If you skip -u on the first push, subsequent git push calls will complain that there is no upstream configured.

git remote -v is the "what is my setup" command. On any unfamiliar repo, running this immediately tells you where fetches and pushes are going. You would be surprised how often this surfaces a remote pointing somewhere unexpected.

git cherry-pick <hash> deserves a mention. It copies a single commit from anywhere in the history onto your current branch. The classic use case: a hotfix was merged to main, but you are working on a long-running feature branch that needs that fix too. Cherry-pick the commit hash and it lands on your branch without the rest of main's changes.

Undoing Mistakes

This is the category people search most urgently. Something went wrong and you need to reverse it without making things worse.

git reset -- soft HEAD~1 is the gentlest undo. It moves the branch pointer back one commit but leaves all the changes staged and ready to recommit. Use this when you committed too early and want to add more changes or rewrite the message.

git reset HEAD~1 (default "mixed" mode) moves the pointer back and unstages the changes, but leaves them in your working tree. Use this when you want to re-examine what you changed before re-staging.

git reset --hard HEAD~1 is the nuclear option. It moves the pointer back and discards the changes entirely. There is no built-in undo for this — the changes are gone from the working tree. Only use it when you are certain you do not want those changes.

git revert <hash> is the right tool when the commit you want to undo has already been pushed. Revert creates a new commit that applies the inverse of the original changes. History is preserved. Your teammates who pulled will not have their world disrupted.

git restore <file> discards working tree changes to a specific file. git restore --staged <file> unstages a file without touching the working tree. These commands were added in Git 2.23 as cleaner alternatives to the overloaded git checkout and git reset, and they are much easier to reason about.

Stashing Work in Progress

Stash is the "I need to switch context right now but I am not ready to commit" escape hatch.

git stash saves your uncommitted changes (both staged and unstaged) to a stack and reverts your working tree to the last commit. You can now switch branches, pull changes, fix a bug — whatever you need. When you come back, git stash pop restores your changes.

git stash push -m "descriptive message" is worth using over bare git stash the moment you have more than one stash entry. The message makes it much easier to identify entries when you run git stash list later. A stash entry named WIP: refactoring auth middleware is a lot more useful than stash@{2}.

git stash apply stash@{1} applies a specific entry without removing it from the list. Useful when you want to apply the same stash to multiple branches, or when you are not ready to commit to popping it yet.

Advanced and Less-Common Commands

The Advanced category covers the commands that come up occasionally but are hard to remember.

git log --oneline --graph --all is a favorite I recommend everyone run on their repos periodically. The ASCII branch graph gives you a visual picture of how your branches relate — which ones have diverged, where merges happened, which tags are where. It is one of those commands that makes abstract version history concrete.

git bisect start begins a binary search to find which commit introduced a bug. You mark a known-good commit with git bisect good <hash> and a known-bad commit with git bisect bad <hash>, and git checks out the midpoint commit for you to test. You keep marking good or bad until git identifies the exact commit that broke things. For bugs that are hard to reproduce without running the code, bisect is invaluable.

git blame <file> shows you who last modified each line of a file and in which commit. The name sounds accusatory — in practice, it is usually used to understand why a line of code is the way it is by looking up the commit and reading its message and diff. Good teams use blame for context, not blame.

git reflog is the rescue command. Even after a hard reset, git keeps an internal log of everywhere HEAD has been. If you accidentally destroyed commits you needed, git reflog will show you the hash you need to recover them with git reset --hard <recovered-hash>. I have seen this save hours of work.

Pro Tips for a Smoother Git Workflow

A few habits that make a meaningful difference:

Write commit messages in imperative mood. "Add authentication middleware" instead of "Added authentication middleware" or "Adding authentication middleware." The convention exists because git's own generated messages (merge commits, reverts) use imperative mood, so your messages integrate naturally.

Commit small and often. Atomic commits — one logical change per commit — make git log readable, make code review easier, and make git bisect effective. Committing once a day with a giant "progress" message defeats most of git's value.

Use .gitignore aggressively. Build artifacts, IDE metadata, environment files — these should never appear in your repository. If git status is cluttered with files you are never going to commit, fix your .gitignore.

Learn the --patch flag. git add --patch (or git add -p) lets you interactively select which hunks of a file to stage. When one file has changes for two different purposes, you can split them into separate commits. This is how you maintain clean, meaningful commit history while working in the messy reality of actual development.

Tools Worth Pairing With This One

If you are spending time with git workflows, a couple of other tools on the site are directly relevant:

Cron Parser — CI/CD pipelines often have scheduled jobs alongside event-triggered ones. If your deployment pipeline includes a cron schedule and you need to decode or build a cron expression, this tool handles it instantly.

URL Encoder — Git remote URLs occasionally include characters that need encoding, especially when authentication credentials or tokens are embedded in the URL. If a remote URL is not being parsed correctly, run it through the encoder first.

FAQ

What is the difference between git fetch and git pull? git fetch downloads new commits and branches from the remote but does not touch your local branches. git pull does a fetch followed by a merge. Fetch when you want to inspect first, pull when you are ready to integrate.

How do I undo a commit I already pushed? Use git revert <commit-hash> to create a new commit that undoes the changes without rewriting history. git reset is only safe for commits that have not been pushed yet.

What is git stash for? Stash temporarily shelves uncommitted changes so you can switch context — switch branches, pull changes, apply a hotfix — without committing half-done work. git stash pop restores the changes when you come back.

When should I use rebase instead of merge? On personal branches where you want a clean linear history before merging into main. Never rebase commits that others have already pulled — it rewrites the hashes and causes conflicts.

How do I recover commits after git reset --hard? Run git reflog to see the history of HEAD positions. Find the commit hash you need and run git reset --hard <that-hash> to restore it.

Wrapping Up

Git is one of those tools that rewards time investment more than almost anything else in a developer's toolkit. The commands that feel arcane become automatic, the workflows that once required a documentation tab become second nature.

The Git Command Generator is there for the in-between phase — when you know what you need to do but cannot quite recall the exact syntax. Bookmark it, use it, and by the time you have used it enough times you will probably have the commands memorized anyway.

Frequently Asked Questions

D

About the author

Daniel Park

Senior frontend engineer based in Seoul. Seven years of experience building web applications at Korean SaaS companies, with a focus on developer tooling, web performance, and privacy-first architecture. Open-source contributor to the JavaScript ecosystem and founder of ToolPal.

Learn more

Share this article

XLinkedIn

Related Posts