Features

Simpler and more powerful UI for Git branches

Lightweight and fast branches are one of the major features and advantages of Git. We in Jetbrains want to make workflow with branches even more convenient and simple than it is in command line.

You might have noticed that in IntelliJ IDEA 11.0 we’ve added new interface to checkout branches from Git. In IntelliJ IDEA 11.1 we have polished the look and feel, and made it more functional. The main goal of new interface is to concentrate on the most common use cases. Let’s take a look at the features which the IDE offers to manage Git branches.

The Git branch popup menu is available from Main Menu | VCS | Git | Branches, from Context Menu | Git | Branches, from the VCS Operations Popup, and also when you click the widget in the status bar, which shows the current Git branch. Personally, I prefer using keyboard, and I’ve assigned a shortcut (Settings | Keymap) to the action.

The popup shows the list of all local and remote branches available. Each branch can be checked out, compared or merged with current branch or deleted.

You may also create and checkout a new branch (like git checkout -b <branch>) and checkout a specific revision or tag.

Have a look at each of these features, since there are some niceties which IntelliJ IDEA offers to user.

Checkout

Usually when you checkout a branch, you have clean working tree, and everything just works. But sometimes you may want to checkout with dirty working tree, and if the local changes would be overwritten by checkout, Git fails with an error.

IntelliJ IDEA handles this situation and offers Smart checkout, which shows the files preventing checkout and offers to stash local changes, checkout the branch, and then unstash changes back. If a conflict happens during unstash, merge dialog is shown.

Checkout as new local branch is just a shorthand for Checkout + New branch. It can be useful if you work on a feature branch and want to start another feature from master.

Checkout remote branch as new local branch serves the same purpose, but in addition to that it sets ups tracking.

Merge

The merge action merges selected branch into the current branch, simply like git merge <branch>. Common workflow is create a feature branch, make changes there, checkout master and merge feature to master.

Merge also captures the error we talked above and proposes Smart merge procedure. On conflict it opens merge dialog.

We have plans to add rebase action here as well, but rebase operation is much more complex than merge, so it will take time. Stay tuned.

When a local branch is merged, you can delete it right away.

Delete

Deleting a local branch fully merged to the current branch is very simple. Just select it in the list, select Delete, and that’s all.

However if a branch is not fully merged, you’ll get a helpful dialog which shows the warning together with the list of unmerged commits and the list of branches selected branch is merged to (if there are such branches). Based on this information you may make a decision to delete the branch right away.

Remote branch is deleted, as usual via git push <remote> :<branch>, but since it is a potentially dangerous operation, it is made with confirmation. If you have local branches tracking the remote branch, you may delete them as well.

Compare

There are two modes of branches comparison: git log and git diff.

Select a branch from the popup and choose Compare. You’ll get a dialog, where there are commits existing in current branch and absent in selected branch, and vice versa.

The diff view allows to show the difference between branches in a single file tree.

That’s all about Git branches for today. We’ll talk more about projects with multiple Git roots configuration in the next post. Stay tuned!

We are looking forward for your feedback on the Git branches new interface. Your suggestions are welcome here and in our issue tracker as always. Please post bugreports directly to the tracker.

image description