Git Course 0%

Under the hood: the command behind every action

Intermediate IntelliJ UI ≈ 8 min

What you will learn

  • The command behind every action you use
  • Which IntelliJ features are not Git at all
  • How to watch the IDE run them

After this lesson you can

  • I can translate between IntelliJ's actions and Git commands in both directions

Why this matters

Instructions arrive as commands; IntelliJ offers actions. This page is the translation, in both directions, and it names the three things IntelliJ does that no Git command does.

The map

IntelliJ Command
Add to VCS (⌘⌥A) git add <file>
Stage a block from the gutter git add -p, for that block
Unstage in the Commit window git restore --staged <file>
Rollback on a file git restore <file>
Commit (⌘K) git commit
Commit and Push… (⌥⌘K) git commit then git push
Amend checkbox git commit --amend
Undo Commit in the Log git reset --soft HEAD~1
Push (⇧⌘K) git push, or git push -u for a new branch
Force push in the push dialog git push --force-with-lease
Update Project (⌘T) git pull, merging or rebasing per the setting
Fetch in the VCS widget git fetch
New Branch git switch -c <name>
Checkout a branch git switch <name>
Checkout and Rebase onto Current git switch <name> then git rebase <previous>
Merge into Current git merge <name>
Rebase Current onto Selected git rebase <name>
Interactively Rebase from Here… git rebase -i <commit>
Cherry-Pick in the Log git cherry-pick <hash>
Revert Commit in the Log git revert <hash>
Reset Current Branch to Here… git reset --soft/--mixed/--hard <hash>
New Branch from Selected Commit git branch <name> <hash>
Stash Changes / Unstash git stash push / git stash pop
Show History on a file git log -- <file>
Annotate with Git Blame git blame <file>
Compare with Current on a branch git log --oneline <branch>..HEAD and the reverse
Abort Merge / Abort Rebase git merge --abort / git rebase --abort
Enable Version Control Integration git init
Clone Repository git clone <url>

The three that are not Git

Feature What it really is
Changelists The IDE's grouping of pending changes. No Git equivalent; invisible to git status (lesson 16.5)
Shelving Patches in the IDE's own storage, not git stash (lesson 16.8)
Local History A record of every save, independent of Git, and the only thing that can recover uncommitted work

Knowing these three are IntelliJ's own explains an otherwise baffling situation: your IDE shows work that git status cannot see, and a colleague looking over your shoulder in a terminal finds nothing.

Watching it happen

The Git tool window's Console tab prints every command as the IDE runs it, with options included:

Text
21:04:11.221: [trailguide] git -c core.quotepath=false commit -m "docs: add Windows steps (#12)"

Ten minutes with that tab open, clicking things, teaches the mapping faster than this table (lesson 16.10).

Where the mapping is loose

  • Update Project is a pull whose strategy depends on a setting, and it may also shelve and unshelve if you have local changes.
  • Smart Checkout is a shelve, a switch and an unshelve.
  • Commit and Push is two commands with one confirmation.
  • Reset Current Branch to Here… offers a fourth mode, Keep, which is git reset --keep: like hard, but it refuses rather than overwriting local changes.

What has no action at all

git reflog and git bisect. The first is the recovery command (lesson 12.1), and the terminal is one keystroke away (⌥F12).

How to do it

Read the table in reverse: given a command, the IntelliJ action is usually findable with Find Action (⇧⌘A) and the command's verb. "Cherry-pick", "revert", "rebase", "stash" and "blame" all match directly.

Common mistakes

  • Assuming everything in the IDE is Git. Changelists, shelves and Local History are not.
  • Looking for the reflog in a menu.
  • Force-pushing without noticing that IntelliJ prefers the lease-checked form and keeps a protected-branch list (lesson 16.10).
  • Not reading the Console when an action surprises you.

Try it yourself

Goal: translate in both directions.

  1. Open the Console tab and perform six actions: add, commit, push, create a branch, stash, revert a commit from the Log.
  2. Write down the command each produced, without looking at the table.
  3. Check your answers against the table above.
  4. Now go the other way: someone tells you to run git reset --soft HEAD~1. Find the equivalent action with Find Action.
  5. Finally, run git switch -c test/mapping in the terminal and watch the VCS widget update.

Expected result: six correct translations, one reverse lookup, and the observation that the IDE and the terminal are two views of the same repository.

Show solution

Step 5 is the reassurance. A command typed in the terminal changes the repository, and the IDE reflects it immediately, because both are reading the same .git directory. That is what makes mixing the two safe, and it is why the three IDE-only features are worth knowing: they are the exceptions.

Check yourself

1. Which of these is not a Git feature?
2. What is Undo Commit in the Log?
3. Where can you see the exact command behind an action?

Key terms

Commit Push Staged Stash