Branch management
Beginner IntelliJ UI
Why this matters
Branching is the operation you do most often after committing, and IntelliJ's branch menu offers more than any other tool in this course. Knowing what each entry does, especially Smart Checkout, means the extra options help rather than confuse.
The VCS widget
The window header shows the current branch. Clicking it opens the branch popup, with local branches, remote branches, recent ones, and favourites marked with a star.
| Entry | Does |
|---|---|
| New Branch | Creates from the current branch and switches to it |
| New Branch from Selected | Creates from another branch, local or remote |
| Checkout | Switches to the selected branch |
| Checkout and Rebase onto Current | Switches, then rebases it onto where you were |
| Compare with Current | Shows the commits and files that differ |
| Show Diff with Working Tree | Compares that branch with your files right now |
| Rename | Renames a local branch only |
| Delete | Deletes a local branch, with an undo link in the notification |
| Push / Update | On a specific branch, without switching to it |
The fetch icon in the widget refreshes the remote branch list, which matters before checking out a branch a colleague has just pushed.
Smart Checkout
Switching branches with uncommitted changes is where Git refuses if the changes touch files that differ (lesson 6.3). IntelliJ offers Smart Checkout, which:
- Shelves your uncommitted changes.
- Switches to the other branch.
- Unshelves them there.
It is convenient and worth understanding rather than accepting blindly. Two consequences: your changes are now on a different branch, which is occasionally not what you wanted; and if the unshelve conflicts, you get a conflict on a branch you have just arrived on. The alternatives IntelliJ offers in the same dialog are Force Checkout, which discards the changes, and Don't Checkout.
The habit that avoids the question: commit or shelve before switching.
Publishing and tracking
A new branch is local until pushed. Git → Push (⇧⌘K) publishes it and sets the upstream, so afterwards the widget shows incoming and outgoing counts for it.
The branch popup marks tracked branches, and Update on a branch fetches and fast-forwards it without switching, which is a genuinely useful trick for keeping main current while you work elsewhere.
Comparing branches
Compare with Current opens a two-pane view: the commits that are on one branch and not the other, in both directions, and the file diffs for any commit you select.
This answers "has my branch got the latest main?" and "what would this merge bring in?" without merging anything, which is worth doing before every merge request.
Merging and rebasing
| Task | Where |
|---|---|
| Merge another branch into this one | Branch popup → the branch → Merge into Current |
| Rebase this branch onto another | Branch popup → the branch → Rebase Current onto Selected |
| Abort either | The banner in the Git tool window, or Git → Abort |
Conflicts open the merge dialog (lesson 16.7), which is the part IntelliJ does better than anything else here.
How to do it
$ git switch -c docs/12-windows-install-steps
$ git switch main
$ git push -u origin docs/12-windows-install-steps
$ git branch -d docs/12-windows-install-steps
$ git log --oneline main..docs/12-windows-install-stepsThe last one is Compare with Current in command form.
The Status Bar branch control does the same core operations with fewer options. See lesson 15.5.
- The VCS widget in the header for everything
- New Branch, New Branch from Selected, Checkout and Rebase onto Current
- Compare with Current, Show Diff with Working Tree
- Find Action (⇧⌘A) → "Branches", "New Branch"
Protected branches refuse a push from the IDE exactly as they would from the terminal, and the merge request page offers Delete source branch at merge time (lesson 9.5).
The same through rulesets, and Delete branch on a merged pull request.
Common mistakes
- Accepting Smart Checkout without knowing it moves your changes to the other branch.
- Choosing Force Checkout, which discards them.
- Renaming a branch and expecting the remote to follow. Rename is local; the remote branch keeps its name.
- Not fetching first, so a colleague's new branch is not in the list.
- Deleting an unmerged branch past the warning (lesson 12.9).
Try it yourself
Goal: use the branch popup for a whole branch life, including Smart Checkout.
- Create
docs/intellij-branch-demowith New Branch. - Make a change and leave it uncommitted, then switch to
mainand accept Smart Checkout. - Look at the Shelf tab during the switch, then switch back and confirm your change returned.
- Commit, push with ⇧⌘K, and read the commit list in the dialog.
- Use Compare with Current from
mainto see what your branch would bring in, then merge and delete it.
Expected result: a branch created, moved between, published, compared, merged and deleted, with one observation of what Smart Checkout does behind the scenes.
Show solution
Step 3 is the point. Smart Checkout is a shelve, a checkout and an unshelve, and seeing the shelf entry appear turns it from magic into three steps you could have done yourself. That matters the day the unshelve conflicts, because then you know exactly where your work is.