Git in VS Code and IntelliJ IDEA

Updated · 11 min read
easyGit 2.53gitvs-codeintellij-ideaidemerge-conflicts

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

JobTerminalVS CodeIntelliJ IDEA
See what changedgit status, git diffSource Control view (Ctrl+Shift+G)Commit tool window (Alt+0, Cmd+0 on macOS)
Stage a filegit add <file>+ next to the fileCheck the file's check box
Stage some linesgit add -pSelect lines in the diff, then Stage Selected RangesCheck individual changes in the diff
Commitgit commit -mType the message, then CommitType the message, then Commit
Amendgit commit --amendCommit (Amend) in the Commit menuAmend check box
Switch or create a branchgit switch, git switch -cBranch name in the status barBranch widget in the title bar
Pull and pushgit pull, git pushSync Changes, or Pull and PushUpdate Project (Ctrl+T), Push (Ctrl+Shift+K)
Stashgit stashStash in the Source Control menuGit, then Uncommitted Changes, then Stash Changes, or Shelve
Historygit log --graphSource Control Graph sectionGit tool window, Log tab (Alt+9)
Who changed a linegit blameHover the line (blame annotations), or a Git extensionRight-click the gutter, Annotate with Git Blame
Resolve a conflictEdit markers, git addMerge editorThree-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.

IDE buttons run the same Git commands

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

  1. Click a file to see its diff side by side.
  2. 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, like git add -p.
  3. Type a message in the box at the top and press Commit (Ctrl+Enter).
  4. Sync Changes pulls and then pushes. Its setting git.rebaseWhenSync decides 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 byIntelliJ, in the project's .idea/shelf folderGit, in refs/stash
Visible in the terminalNoYes, git stash list
Can save part of a fileYes, single changesYes, with git stash push -p
Works with any version controlYesGit 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:

Terminal
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)"
Output
core.editor code --wait
diff.tool vscode
merge.tool vscode

Explanation: --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 forThe terminal is better for
Reviewing and staging single lines with the code in viewAnything the IDE has no button for: reflog, bisect, filter-repo, worktree, sparse-checkout
Resolving conflicts in a three-pane viewSeeing exactly what happened, in Git's own words and messages
Blame and history next to the codeScripts, CI jobs, hooks and aliases
Quick daily commits, pulls and pushesRecovering from mistakes, where every step should be deliberate
Interactive rebase as a tableWorking 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
Terminal
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.cmd
Output
intellij
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.

Quick check: Git in the IDE

4 questions
1Which Git does VS Code use?
2In VS Code's conflict view, what is "Current Change" during a merge?
3Where does IntelliJ IDEA store shelved changes?
4What does --wait do in core.editor "code --wait"?

Key Takeaways

Quick reference

Setting or commandIt is used to
git config --global core.editor "code --wait"Edit messages in VS Code
git config --global merge.tool vscodeResolve conflicts in VS Code
git mergetoolOpen the merge tool for each conflicted file
git difftoolCompare versions in the diff tool

Was this tutorial helpful?

Lesson 98 of 106