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.
This is great.
It would be great to see the same kind of UI for Mercurial.
See this is the kind of love Mercurial is missing, oh and this is what makes Idea so damn great.
love the stash-checkout-unstash automation…
But there is still nothing for handling tags ..
It would be really excellent if Pull/Push/Fetch were added as shortcuts in the plugin pane somewhere, instead of from the VCS drop down menu at the top. That’s my only real complaint with the plugin.
When will the next Git post be ready?
@Kevin
Do you want Pull/Push/Fetch to be added to the popup menu described in the topic? Or you just want an easier access to these functions? In the latter case you may want to use the VCS Operations Popup, or make your own Quick List.
When I’m in the changes window and I do compares, or compare to local, most of the windows just show checksum’s at the top. I haven’t a clue what is being compared with? Local branch, remote repo? Really confusing when you have your personal remote repo and your upstream remote repo.
The diff window should label the left and right file better at the top.
@AaronLS
Yep, that is a known problem, please vote: http://youtrack.jetbrains.com/issue/IDEA-68422
It would be great if you were able to search the branch , when you have many branches is imposible to select now.
I agree. We need this badly because of 5000+ branches :/
Just open the popup and begin typing the name of the branch. Speedsearch is there.
I’m greatly missing the compare between 2 commits. (in the history)
And the compare with local too.
Used it a lot to see if commit were squashabble…
It is possible to compare any two revisions from a file history.
From the log it is not possible, there are similar requests:
https://youtrack.jetbrains.com/issue/IDEA-100431
https://youtrack.jetbrains.com/issue/IDEA-125616
What about a quick commit option? without a dialog, something similar to vs code vcs tool window?
We are considering such a feature at the moment. As a marker, follow https://youtrack.jetbrains.com/issue/IDEA-63394
Why does the checkout as new local branch of a remote track the original remote (and push to it)? If I then manually push to a new remote, it is still tracking the old. Is there anyway to change this.
I was expecting this to work just like branching a local, i.e. it creates a new local branch and that branch (by default) pushes to a new remote and then tracks it. I guess I can see it tracking initially the original remote, but seems like it should give you a choice.
Checkout as anew local branch executes
git checkout -b LocalBranch remotebranchcommand which sets the tracking.If you want to create a new branch without tracked remote, use the New branch action. This action behaves as a local branching.
Is there a way to ‘reverse compare’ in IntelliJ?
Current feature:
Lower Right -> select branch -> Compare: Compares to
Required feature:
Lower Right -> select branch -> Reverse Compare: Compares the to
As a workaround I can check out the other branch and then compare to the one I previously had active, but it’s a hassle when you need to do that a few times.
Another option would be to add a ‘flip’ button in to the ‘Comparing with ‘ Window.
Fixing my previous comment because of formatting issues:
Is there a way to ‘reverse compare’ in IntelliJ?
Current feature:
Lower Right -> select branch -> Compare: Compares “current branch” to “selected branch”
Required feature:
Lower Right -> select branch -> Reverse Compare: Compares the “selected branch” to “current branch”
As a workaround I can check out the other branch and then compare to the one I previously had active, but it’s a hassle when you need to do that a few times.
Another option would be to add a ‘flip’ button in to the ‘Comparing with ‘ Window.
There is a “Swap Branches” link at the Files page (previously and in the blog post named “Diff”) of the Compare dialog.