Projects Blog Tools Music Contact
← All Posts
Productivity September 6, 2026

Git Commands That Save Hours: 10 Worth Learning Now

By: Evgeny Padezhnov

Illustration for: Git Commands That Save Hours: 10 Worth Learning Now

Most developers learn six Git commands and stop. Clone, add, commit, push, pull, checkout. That set covers daily work. It also guarantees a messy history, painful conflicts, and the occasional overwritten branch.

The commands below are not exotic. They ship with Git. They solve problems that teams otherwise solve with Slack messages and re-cloning the repo. Tricentis catalogs 70 essential Git commands across Setup, Daily, Branching, Undoing, Inspecting, Collaboration, and Advanced categories. Most people use a fraction of them.

Key point: the value is not memorizing syntax. It is knowing which problem each command already solves.

1. git add -p — stage changes, not files

One file often holds two unrelated changes. A bug fix and a debug print. A feature and a stray formatting tweak.

git add -p src/payment.js

Git walks through each hunk and asks what to do. Press y to stage, n to skip, s to split a hunk into smaller pieces, e to edit the patch by hand.

Tricentis describes the patch flag as a way to "interactively choose specific hunks of changes within the file." The result is commits that describe one thing.

Common mistake: running git add . out of habit, then writing a commit message that lists three unrelated changes. Reviewers slow down. Reverting later becomes surgery.

2. git commit --amend — fix the last commit

A forgotten file. A typo in the message. A missing test.

git add tests/payment.test.js
git commit --amend --no-edit

--no-edit keeps the existing message. Drop it to rewrite the message too.

Amend rewrites the last commit, so it creates a new hash. Safe on local commits. Dangerous on commits already pushed to a shared branch, unless the branch belongs to one person and the team agreed on it.

3. git pull --rebase — stop generating merge noise

git pull is not one operation. As RhodeCode explains, it is "a shortcut for two different actions: git fetch (getting the data) and git merge (combining it)."

That hidden merge is where spaghetti history comes from. RhodeCode recommends git pull --rebase to keep the timeline linear and readable.

Make it the default:

git config --global pull.rebase true

Mike Madison goes further. His Git philosophy post names git pull as the one command to forget entirely. His preferred sequence is explicit:

git fetch upstream
git rebase upstream/develop

His warning about accumulated merge commits is concrete. History becomes hard to read. Commit order gets lost. Feature branches can start undoing work without the developer noticing.

In plain terms: fetch is safe and changes nothing in the working tree. Madison notes this "commonly causes confusion" because nothing appears to happen. Nothing is supposed to happen. Fetch updates remote tracking refs, and the developer decides what comes next.

4. git push --force-with-lease — the force push that checks first

Rebasing rewrites history. Pushing rewritten history requires force. Plain --force overwrites the remote unconditionally, including commits a teammate pushed thirty seconds ago.

git push --force-with-lease

Tricentis lists this as the "safe force push." Git compares the remote ref against what the local clone last saw. If someone else pushed in the meantime, the push is rejected instead of destroying their work.

Tested in production: teams that ban force pushes outright usually end up with worse history than teams that standardize on --force-with-lease. The command removes the actual risk, not the useful capability.

Common mistake: aliasing push -f for convenience. The alias survives long after the reasoning behind it. Alias --force-with-lease instead.

5. git log --oneline --graph --all — read history in one screen

Long log output hides structure. This combination shows the shape of the repository.

git log --oneline --graph --all --decorate

RhodeCode calls it a "visual representation of your repository's history." Branch points, merges, and divergence become visible without a GUI.

Worth turning into an alias:

git config --global alias.lg "log --oneline --graph --all --decorate"

RhodeCode also recommends team-wide aliases as a strategic practice, not personal preference. Shared aliases mean shared vocabulary during incidents.

6. git rerere — never resolve the same conflict twice

Tricentis lists git rerere under Advanced with a short definition: "Reuse conflict resolutions."

Long-running branches produce the same conflict on every rebase. Rerere records how the conflict was resolved and replays that resolution automatically next time.

git config --global rerere.enabled true

That is the whole setup. Git then records resolutions silently. The next time the identical conflict appears, it resolves itself and Git says so.

Key point: rerere pays off exactly where the pain is worst. Frequent rebases of a branch that has drifted from main.

The better fix is upstream. Atlassian's workflow guide recommends short-lived branches, because "the longer a branch lives separate from the production branch, the higher the risk for merge conflicts and deployment challenges." Rerere reduces the cost of the symptom. Short branches remove the cause.

7. git stash — park work without a junk commit

Urgent bug arrives mid-feature. The working tree is dirty. Branch switching fails.

git stash push -m "wip: checkout form validation"
git switch hotfix

Naming the stash matters. An unnamed stash list is unreadable after two days.

Restore it with git stash pop to apply and delete the entry, or git stash apply to apply and keep it. Keeping it is safer when the stash might need to land on a second branch.

Common mistake: stashing everything for a week. Stashes are invisible to teammates and easy to lose during a clone or machine change. For anything longer than a few hours, use a branch.

8. git cherry-pick — move one commit, not a branch

A single fix lives on a feature branch. Production needs it now. The rest of the branch is unfinished.

git log --oneline feature/checkout
git switch main
git cherry-pick a1b2c3d

Cherry-pick copies the change as a new commit with a new hash. Use -x to append the original hash to the message, which keeps the trail traceable.

Cherry-pick multiple commits by listing them, or use a range with git cherry-pick a1b2c3d..e4f5g6h.

Common mistake: cherry-picking a commit that will later be merged anyway. Duplicated changes create confusing conflicts at merge time. Pick when the branches genuinely diverge, not to skip waiting for a review.

9. git revert — undo without erasing

git reset --hard destroys commits. On a shared branch, that means someone else's history disappears.

git revert a1b2c3d

Revert creates a new commit that reverses the change. Original commit stays in history. Anyone reading the log later sees both the mistake and the correction.

For a merge commit, specify the parent:

git revert -m 1 <merge-commit>

Key point: reset for local mistakes, revert for anything already pushed. That single rule prevents most force-push incidents.

10. git show — inspect a commit without leaving the terminal

GitHub's list of top Git commands describes git show as a way to see the changes made on the current branch and review project history.

git show                 # last commit, full diff
git show a1b2c3d         # a specific commit
git show a1b2c3d:src/api.js   # a file as it existed then

That last form is the underrated one. It prints a file at a historical revision without checking anything out. Useful for answering "when did this config value change" without disturbing the working tree.

Pair it with git diff, which RhodeCode describes as showing exactly which lines changed since the last commit, and git status, which the same source calls the developer's "North Star."

Configuration worth doing once

git config is the first command to run after installing Git, per GitHub's guide:

git config --global user.name "username"
git config --global user.email "you@example.com"

Two more settings that earn their place:

git config --global rerere.enabled true
git config --global pull.rebase true

RhodeCode also recommends Git hooks to run tests or linting automatically, sparse checkout for large monorepos, and secret-scanning tools to prevent accidental leakage of API keys or passwords. Hooks belong in the repo, not in each developer's head.

Commands do not replace a workflow

Better commands will not fix a broken process. The team-level sources are consistent on this point.

Atlassian defines a Git workflow as "a recipe or recommendation for how to use Git to accomplish work in a consistent and productive manner," and notes there is no standardized process because Git prioritizes flexibility. The team has to pick one.

Dropanote's analysis of branching strategies is blunter. Teams often choose Git Flow "because it sounds serious, not because they analyzed whether it solves their problems." The article adds that Git Flow "can organise existing quality processes, but it cannot replace missing ones."

That reframes the conflict problem. Disbug lists merge conflict rate as a workflow metric and argues that frequent conflicts signal branch management or collaboration issues. Rerere hides the symptom. Shorter branches and clearer ownership fix it.

GitKraken's guidance is procedural and cheap to adopt: document branch, commit, and merge conventions, set up commit message and pull request templates, and run regular training so the whole team uses the same workflow.

Try it right now

Enable one setting and one alias. Both take under a minute:

git config --global rerere.enabled true
git config --global alias.lg "log --oneline --graph --all --decorate"

Then run git lg in the largest repository available. The shape of the history usually explains more about the team's workflow than any documentation does.

Frequently Asked Questions

How do I include a forgotten change in my last commit without creating a new one?

Stage the change, then run git commit --amend --no-edit. The commit message stays the same and the file joins the existing commit. Only do this on commits that have not been pushed to a shared branch.

How do I apply a specific commit from another branch to my current work?

Find the hash with git log --oneline <branch>, then run git cherry-pick <hash> on the target branch. Add -x to record the original hash in the new commit message for traceability.

How do I safely force push after rebasing without overwriting teammates' changes?

Use git push --force-with-lease instead of --force. Tricentis lists it as the safe force push because Git rejects the operation if the remote moved since the last fetch. Plain --force overwrites unconditionally.

What is the difference between git stash apply and git stash pop?

pop applies the stash and deletes the entry. apply applies it and keeps the entry in the stash list. Use apply when the same changes may need to land on more than one branch.

How do I safely undo a commit while keeping it visible in the history?

Run git revert <hash>. Git creates a new commit that reverses the change while leaving the original in the log. Reserve git reset --hard for local commits that were never pushed.

Information is accurate as of the publication date. Terms, prices, and regulations may change — verify with relevant professionals.

✦ Squeeze AI
  1. Splitting `git add -p` into per-hunk staging lets a single file with two unrelated edits (e.g., a bug fix and a debug print) be committed separately, keeping each commit focused on one change.
  2. `git commit --amend` folds a forgotten file or message fix into the last commit, but since it produces a new commit hash it is safe only for local, unpushed commits and risky on a commit already shared on a team branch.
  3. `git pull` silently runs fetch and merge together, and that hidden merge step is what produces tangled history; setting `pull.rebase true` (or running `git fetch` followed by `git rebase`) keeps the commit timeline linear and readable.

Powered by B1KEY