The Hook (The "Byte-Sized" Intro)
You type git commit and suddenly you're trapped in Vim. You don't know how to type. You don't know how to quit. Millions of developers have been there. The fix is one line: git config --global core.editor "code --wait". Set your editor once, and every Git operation that needs text input uses the tool you actually know.
📖 What is Editor and Tooling?
Git uses external tools for text editing (commit messages, rebase), diff viewing, and merge conflict resolution. You can configure which tools Git uses.
Conceptual Clarity
Configurable tools:
| Setting | What It Controls | Default |
|---|---|---|
core.editor | Commit messages, rebase instructions | vi or $EDITOR |
diff.tool | Visual diff viewer | None (uses terminal diff) |
merge.tool | Merge conflict resolver | None (manual editing) |
When Git opens your editor:
git commit(without-m)git rebase -i(interactive rebase)git merge(when writing merge commit message)git tag -a(without-m)
Popular diff/merge tools:
| Tool | Type | Config |
|---|---|---|
| VS Code | Editor + Diff + Merge | code --wait --diff |
| Meld | Diff + Merge | meld |
| Beyond Compare | Diff + Merge | bcomp |
| Vimdiff | Diff + Merge | vimdiff |
| opendiff | Diff (macOS) | opendiff |
Real-Life Analogy
Using Git without configuring your editor is like being handed a toolbox in a foreign language. Everything works, but you can't read the labels. Setting your editor is choosing tools you already know.
Visual Architecture
Why It Matters
- Productivity: The right editor makes commit messages and rebases fast.
- Conflict resolution: Visual merge tools make resolving conflicts intuitive.
- Onboarding: New team members shouldn't fight their tools.
- Consistency: Once set, Git always uses your preferred tools.
Code
# ─── Set your editor ───
git config --global core.editor "code --wait" # VS Code
git config --global core.editor "vim" # Vim
git config --global core.editor "nano" # Nano
git config --global core.editor "subl -n -w" # Sublime
# ─── Set diff tool ───
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
# ─── Set merge tool ───
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'
# ─── Use your diff tool ───
git difftool HEAD~1 # Opens visual diff
# ─── Use your merge tool during conflict ───
git mergetool # Opens visual merge resolver
# ─── Suppress backup files from mergetool ───
git config --global mergetool.keepBackup falseKey Takeaways
- Set
core.editorto avoid being trapped in an unfamiliar editor. - Visual diff/merge tools make code review and conflict resolution much easier.
--waitflag is critical — it tells Git to wait until you close the editor.- Configure once globally; override per-repo if needed.
Interview Prep
-
Q: Why is
--waitneeded when setting VS Code as Git's editor? A: Without--wait, Git opens VS Code and immediately continues, treating the empty/unchanged file as the input.--waittells Git to pause until you close the file in VS Code, giving you time to write your commit message. -
Q: What is the difference between
diff.toolandgit diff? A:git diffshows diffs in the terminal.git difftoolopens your configured visual diff tool (e.g., VS Code, Meld). The visual tool provides side-by-side comparison with syntax highlighting. -
Q: How do you resolve merge conflicts with a visual tool? A: Set
merge.toolin your config, then rungit mergetoolduring a conflict. Git opens each conflicted file in your configured merge tool, where you can visually pick changes.