Git in VS Code and IntelliJ IDEA
An IDE Git integration is the part of an editor such as VS Code or IntelliJ IDEA that runs Git for you through buttons, panels and keyboard shortcuts. Both editors use the Git installed on your computer, so everything they do is an ordinary Git command, and the result is the same repository you see in the terminal. It is used to do the everyday work (staging, committing, switching branches, pulling, pushing and resolving conflicts) without leaving the code, and to see changes right next to the lines they affect.
It is like the automatic gearbox in a car. It changes the same gears as a manual one, just for you. Knowing how the gears work, as this course has taught, means you understand what the car is doing, and you can take over when it does something odd.
The Same Jobs in Each Place
| Job | Terminal | VS Code | IntelliJ IDEA |
|---|---|---|---|
| See what changed | git status, git diff | Source Control view (Ctrl+Shift+G) | Commit tool window (Alt+0, Cmd+0 on macOS) |
| Stage a file | git add <file> | + next to the file | Check the file's check box |
| Stage some lines | git add -p | Select lines in the diff, then Stage Selected Ranges | Check individual changes in the diff |
| Commit | git commit -m | Type the message, then Commit | Type the message, then Commit |
| Amend | git commit --amend | Commit (Amend) in the Commit menu | Amend check box |
| Switch or create a branch | git switch, git switch -c | Branch name in the status bar | Branch widget in the title bar |
| Pull and push | git pull, git push | Sync Changes, or Pull and Push | Update Project (Ctrl+T), Push (Ctrl+Shift+K) |
| Stash | git stash | Stash in the Source Control menu | Git, then Uncommitted Changes, then Stash Changes, or Shelve |
| History | git log --graph | Source Control Graph section | Git tool window, Log tab (Alt+9) |
| Who changed a line | git blame | Hover the line (blame annotations), or a Git extension | Right-click the gutter, Annotate with Git Blame |
| Resolve a conflict | Edit markers, git add | Merge editor | Three-pane Merge dialog |
Menu names and shortcuts change from version to version; these are the ones for the 2026 releases of both editors, with Windows and Linux shortcuts.
VS Code
VS Code has Git built in. Open a folder that contains a repository, and the Source Control view lists changed files in two groups: Staged Changes and Changes.
Staging and Committing
- Click a file to see its diff side by side.
- Click
+next to a file to stage it, or select some lines in the diff and run Stage Selected Ranges (right-click, or the command palette) to stage only those lines, likegit add -p. - Type a message in the box at the top and press Commit (
Ctrl+Enter). - Sync Changes pulls and then pushes. Its setting
git.rebaseWhenSyncdecides whether the pull rebases.
Branches and History
The branch name in the bottom-left status bar opens a list to switch to, create or check out a remote branch. The Source Control Graph section shows the commit graph of the current branch and its upstream. For more history tools, such as file history and blame for every line, many developers add the GitLens extension.
Resolving Conflicts
When a merge or rebase stops with a conflict, VS Code marks each conflict in the file with Accept Current Change, Accept Incoming Change and Accept Both Changes. "Current" is your branch (HEAD) and "incoming" is the branch being merged, as in "Resolving Merge Conflicts" (during a rebase, the two are swapped). Resolve in Merge Editor opens a three-way view: theirs, ours, and the result below. Save, stage the file, and continue the merge or rebase from the Source Control view.
IntelliJ IDEA
IntelliJ IDEA (and the other JetBrains IDEs) has its own Git screens. Turn version control on with VCS, then Enable Version Control Integration, or open a project that already has a .git folder.
Committing
The Commit tool window lists changes in changelists. Check files or single changes in the diff to choose what goes into the commit; IntelliJ stages them for you when you press Commit. Before committing, it can reformat code, optimize imports and run inspections or tests, each a check box under the message (the gear icon). Commit and Push does both at once.
Shelve vs Stash
IntelliJ has two ways to put work aside:
| Shelve (IntelliJ) | Stash (Git) | |
|---|---|---|
| Stored by | IntelliJ, in the project's .idea/shelf folder | Git, in refs/stash |
| Visible in the terminal | No | Yes, git stash list |
| Can save part of a file | Yes, single changes | Yes, with git stash push -p |
| Works with any version control | Yes | Git only |
Use stash if you also work in the terminal, so both places see the same saved work.
History, Annotate and Interactive Rebase
The Log tab of the Git tool window shows the graph of all branches, with filters for branch, author, date and path. Right-click a commit for Cherry-Pick, Revert Commit, Reset Current Branch to Here (soft, mixed, hard or keep) or Interactively Rebase from Here, which opens the to-do list of "Interactive Rebase" as a table where you choose pick, reword, squash, fixup or drop for each row. In the editor, right-click the line numbers and choose Annotate with Git Blame to see who last changed each line.
Resolving Conflicts
When a merge conflicts, IntelliJ lists the files with Accept Yours, Accept Theirs and Merge.... Merge... opens three panes: your version on the left, theirs on the right, and the result in the middle, starting from the common base. Non-conflicting changes can be applied with one click (the magic wand icon), and IntelliJ marks the file as resolved (git add) when you press Apply.
Using Your IDE from Git
Git can also call your editor. These settings make Git open VS Code for commit messages, diffs and merges:
git config --global core.editor "code --wait"
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff "$LOCAL" "$REMOTE"'
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait --merge "$REMOTE" "$LOCAL" "$BASE" "$MERGED"'
git config --global --get-regexp "^(core\.editor|diff\.tool|merge\.tool)"core.editor code --wait
diff.tool vscode
merge.tool vscodeExplanation: --wait makes the code command wait until you close the tab, so Git knows when you have finished. Now git commit without -m, git rebase -i, git difftool and git mergetool (see "Diff and Merge Tools") open VS Code. For IntelliJ IDEA, the command-line launcher is idea and its merge command is idea merge "$LOCAL" "$REMOTE" "$BASE" "$MERGED"; turn the launcher on under Tools, then Create Command-line Launcher, or with JetBrains Toolbox.
When the Terminal Is Better, and When the IDE Is
| The IDE is better for | The terminal is better for |
|---|---|
| Reviewing and staging single lines with the code in view | Anything the IDE has no button for: reflog, bisect, filter-repo, worktree, sparse-checkout |
| Resolving conflicts in a three-pane view | Seeing exactly what happened, in Git's own words and messages |
| Blame and history next to the code | Scripts, CI jobs, hooks and aliases |
| Quick daily commits, pulls and pushes | Recovering from mistakes, where every step should be deliberate |
| Interactive rebase as a table | Working on a server over SSH, with no IDE |
Most professionals use both: the IDE for the daily loop, the terminal when something unusual happens. This course taught the terminal first, because every IDE button maps to a command you now know.
Common Mistakes
Pressing Sync or Update without knowing whether it merges or rebases. Check the IDE's setting, or set pull.rebase in Git, which IDEs respect.
Committing everything by accident. Smart commit in VS Code and pre-checked changelists in IntelliJ include files you didn't mean to. Look at the list before committing.
Shelving in IntelliJ, then looking for the work with git stash list. Shelves aren't Git stashes.
Committing IDE files. Add .idea/, *.iml and .vscode/ (except shared settings you agree on) to .gitignore, as "Git for Java Projects" shows.
Trusting "Accept Both" blindly. It keeps both sides one after the other, which is rarely correct code. Read the result.
Under the Hood
VS Code's Git support is a built-in extension that runs the git program and reads its machine-readable output, such as git status --porcelain=v2, so its picture always matches Git's. IntelliJ IDEA also runs your installed git program (the path is under Settings, then Version Control, then Git), and adds its own features on top, such as changelists and shelves, which Git knows nothing about. Both watch the .git folder for changes, which is why a commit made in the terminal appears in the IDE within a second or two. Because they call the same program, your .gitconfig, hooks, aliases and .gitattributes all apply in the IDE too.
Interview Corner
Does an IDE's Git integration use a different Git?
No. VS Code and IntelliJ IDEA run the Git installed on your computer, so commits, branches and settings are the same in the IDE and the terminal.
What is the difference between shelve in IntelliJ IDEA and git stash?
A shelf is stored by IntelliJ in the project's .idea/shelf folder and works with any version control system; a stash is stored by Git and is visible to every Git tool. Both put uncommitted work aside.
How do you make Git open VS Code for commit messages?
git config --global core.editor "code --wait". The --wait flag makes Git wait until you close the tab.
When would you use the terminal instead of the IDE?
For anything the IDE doesn't offer (reflog, bisect, worktrees, filter-repo), for recovery work where each step matters, in scripts and CI, and on servers without an IDE.
Practice
Challenge: IntelliJ as the merge tool. Configure Git to use IntelliJ IDEA for merges, with the tool name intellij, and print the two settings you created.
What does Git print? Before you open the solution, decide which variables the command needs and in what order.
Show solution
git config --global merge.tool intellij
git config --global mergetool.intellij.cmd 'idea merge "$LOCAL" "$REMOTE" "$BASE" "$MERGED"'
git config --global --get merge.tool
git config --global --get mergetool.intellij.cmdintellij
idea merge "$LOCAL" "$REMOTE" "$BASE" "$MERGED"The single quotes keep $LOCAL and the others as text, so that Git, not your shell, fills them in when git mergetool runs: your version, theirs, the common base, and the file to write the result to.
Checkpoint. In your IDE, make a change to three lines of a file, stage only one of them, commit it, and then run git log -1 -p and git diff in the terminal to confirm that exactly that line was committed and the other two are still unstaged.
Key Takeaways
Quick reference
| Setting or command | It is used to |
|---|---|
git config --global core.editor "code --wait" | Edit messages in VS Code |
git config --global merge.tool vscode | Resolve conflicts in VS Code |
git mergetool | Open the merge tool for each conflicted file |
git difftool | Compare versions in the diff tool |
Was this tutorial helpful?