メインコンテンツへ移動 / Skip to main content

Git Commands Masterclass10 Hidden Features You Can't Afford to Miss

Beyond git add and commit! Learn Git's powerful hidden features from basics to advanced techniques. Master practical tricks like git stash -p, worktree, and reflog that professionals use daily.

Technology
Published on: October 10, 2025
Read time: 5 min
Author: Pochang Lab
Read time: 5 min

Git Commands Masterclass: 10 Hidden Features You Can't Afford to Miss

Introduction

Do you use Git on a daily basis? git add, git commit, git push, git pull... You're already familiar with these commands, right?

However, Git has many more commands and hidden features that "only advanced users know how to master."

Today, let's systematically explore these Git "power tools," from reviewing the basics to advanced usage.


Chapter 1: Organizing Basic Commands

First, let's review the common Git commands used in everyday workflows.

Operation Command Example Description
Stage files git add filename Add to commit target
Check status git status Check changes and staging status
Commit git commit -m "message" Save to local repository
Push to remote git push origin main Upload to GitHub, etc.
Fetch changes git pull Get differences from remote
View history git log --oneline Check history in short format

These are the "everyday conversation" level of Git. Now, let's introduce some powerful features that will "dramatically speed up your work."


Chapter 2: Handy Commands Even Intermediate Users Don't Know!

git diff --staged

You know git diff, right? However, adding the --staged option allows you to check "only the differences that have been staged (added)."

bash
git diff --staged

In other words, you can compare the "two states" of files where you made further modifications after adding them. This allows you to clearly distinguish between "what will be committed" and "changes not yet staged."

Pro tip: git diff alone shows changes that haven't been added yet.
Only with git diff --staged can you see "what's scheduled for commit."

git restore --staged

"Wait, I want to remove this file from the commit!" That's when git restore --staged comes in handy.

bash
git restore --staged filename

We used to use git reset HEAD filename, but now restore is recommended. It's more intuitive and readable. Think of it as "restoring from staging."


git stash -p

git stash temporarily saves your work. But did you know? Adding the -p (patch) option lets you interactively choose which changes to stash.

bash
git stash -p

You can select line by line: "stash this" or "keep this," making it perfect for fine-tuned adjustments. It's also useful when you want to move partial changes to a different branch.


git worktree

If you know this one, you're quite advanced!

Normally, you can only check out one branch per repository. However, with git worktree, you can work on different branches of the same repository in separate directories simultaneously.

bash
git worktree add ../feature-A feature/A

This creates a new folder ../feature-A with the contents of the different branch. It's very convenient when handling test branches and release branches in parallel.


git switch and git restore

git checkout used to be the Swiss Army knife, but now the functionality is split.

Purpose New Command Old Command
Switch branches git switch branch-name git checkout branch-name
Restore files git restore filename git checkout -- filename
✅ These two commands solve the "checkout is too complicated" problem.
They're more readable for beginners and safer to use.

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

A magical log command that beautifully visualizes branch structure.

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

This shows you a "branching history" like this:

code
* 8abf9e3 (HEAD -> main) Merge branch 'feature/ui'
|| * a712dfe (feature/ui) Add new button
* | 57ac03c Fix typo
|/
* 1ac923e Initial commit

In team development, you can see at a glance "where each branch diverged."


git reflog

"I deleted my commit!" "I can't go back after reset!" This command is your "last resort" in such situations.

bash
git reflog

Git records all HEAD movement history. Even if you reset --hard, you can recover if the previous commit ID remains in reflog.

💡 Pro tip: Surprisingly, Git is "designed with failures in mind."
As long as reflog exists, most accidents can be recovered.

git cherry-pick

When you want to incorporate only specific commits from another branch.

bash
git cherry-pick <commit-id>

Instead of merging everything, this is perfect for pinpoint "I just want this fix" scenarios. Ideal for emergency fixes and hotfixes.


git bisect

This is the "detective command." It automatically identifies "which commit introduced the bug."

bash
git bisect start
git bisect bad
git bisect good <commit-id>

Git automatically checks out intermediate commits, so you can find "where it broke" through binary search. With test automation, it works like a "bug hunter AI."


git clean -fd

A command to sweep away "untracked files" in your working tree.

bash
git clean -fd

Useful when you want to remove build artifacts or temporary files. However, be careful as it's irreversible! Adding -n lets you preview.

bash
git clean -fdn

Chapter 3: Tips for Making Git Even More Convenient

1. Register Shortcuts for Frequently Used Commands

If typing long commands every time is tedious, you can set up aliases in .gitconfig.

bash
git config --global alias.st status
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --decorate --all"

Now you can use: git lg → Beautiful history display git stgit status These convenient shortcuts are at your fingertips.


2. Master "Two Worlds" Simultaneously

The beauty of Git lies in "combining experimentation with safety." Run multiple environments in parallel with worktree, save temporarily with stash, and go back in time with reflog. Combining these features allows you to "experiment without fear of breaking things."


Chapter 4: Summary

So, how was that?

Git may seem difficult at first, but internally it's designed very "humanely." It anticipates mistakes and has a structure that allows do-overs. Understanding this makes version control suddenly feel liberating.

Today's Key Commands Summary:

Feature Command Example Effect
Check staged diff git diff --staged Check status before commit
Unstage git restore --staged Cancel add
Partial stash git stash -p Save only parts of changes
Multiple worktrees git worktree Work on branches simultaneously
Visualize logs git log --graph --oneline --decorate --all See branch flow clearly
Recovery command git reflog Recover from mistakes
Selective import git cherry-pick Import specific commits
Bug tracking git bisect Identify bug location
Cleanup git clean -fd Delete untracked files
Alias setup git config --global alias.◯◯ Shorten commands

Conclusion

Git is a "dialogue tool with your past self." Each commit is a message to your future self. Master these convenient commands, and your work efficiency will multiply, while your peace of mind will increase tenfold.

Next time, let's learn about workflow optimization combined with GitHub (gh CLI, Actions, Secrets management, etc.).

Related Articles

October 25, 2025

How to Choose the Best Cursor Plan: Pro vs Pro+ vs Ultra (2025 Edition)

A comprehensive comparison of Cursor's latest pricing plans (Pro, Pro+, Ultra) using mathematical formulas. Learn how to choose the optimal plan based on your monthly usage and when Ultra becomes the best choice.

TechnologyRead more
October 10, 2025

Complete Guide to Devin AI Developer Agent – The 2026 Ecosystem and the Reality of Autonomy

A deep dive into Devin, the leading AI developer agent, as of August 2026. Explore its desktop integration, the new subscription model vs. enterprise ACU, Cursor comparisons, and realistic operational best practices.

TechnologyRead more
August 6, 2026

Why the Same AI Model Yields Different "Intelligence": The Hidden Prompt Transformations and Autonomous Loops Inside Modern IDEs

"Why do I get different results when using the exact same Claude Opus 5 model?" We dive deep into the "black magic" (context injection, prompt transformation, and hidden LGTM loops) that IDEs perform behind the scenes. Exploring the architectures of Cursor, Claude Code, Devin Desktop, and ChatGPT Codex.

TechnologyRead more
November 10, 2025

What is ngrok? Complete Guide to Exposing Local Servers to the Internet

Learn about ngrok, a powerful tool that exposes local web apps and APIs to the internet. Discover its technical mechanisms, history, business model, and security considerations.

TechnologyRead more
October 17, 2025

Too Many Developers in Companies - Why Small Teams Can Develop Faster

Exploring why adding more developers doesn't increase development speed, with real examples from Spotify and Netflix, plus AI automation insights for building efficient small teams.

TechnologyRead more