Git Branches for Multi-root Projects

Sometimes there is a need to have multiple Git repositories within a single project. Since long ago IntelliJ IDEA is able to execute many Git operations on all roots at once: Commit, Update Project, Push. Now multi-repository support has come to branches.

In IntelliJ IDEA 11.1 we have implemented two different approaches for multi-root branches.

Most people who use multi-root setup probably have a single repository for project development and several repositories for libraries. They may be included as submodules or just as nested roots, it doesn’t matter for now. For these everything is simple. When you invoke Git Branches popup, you see all branches in the current repository. Other repositories are accessible from the popup as sub-popups with all branches listed there for each repository, with all usual branch actions available for them.

What is the current repository? If you have explicitly selected a file or folder in the Project View or elsewhere, we take the root under which the file is located. Otherwise (if you clicked on the status bar widget or from the main menu) we take the root of the file currently open in the editor.

Synchronous branch control

There is also another case: when users have several repositories in one project that are connected. We at Jetbrains have a configuration like this in one of our projects. There are 3 repositories in a single project, and these repositories are controlled synchronously, i.e. we commit, push and apply other operations to all 3 repositories at once. For such projects IntelliJ IDEA allows to control branches synchronously. It means performing all branch operations on several repositories simultaneously, as it would be a single repository.

When you invoke Git Branches for the first time, IDEA looks at the repositories registered in the project, and if they all are on branches with same names, proposes to control branches synchronously.

If you don’t need it, you may disable it right away or later in the Settings | Version Control | Git | Control branches from different roots synchronously.

If the setting is enabled, all operations on Git branches will be executed for all repositories at once. On the root level of Git Branches popup there will be listed only those local and remote branches which are common for all repositories in the project. Creating new branch from the popup will create it on all repositories, checking out a branch will checkout it on all repositories, etc. This applies to all actions including checkout, merge and delete. Compare just shows the standard dialog with additional selector to choose the root.

You may still control branches individually for each root by using repository selector in the popup. If you happen to checkout a branch only on one of the roots, you’ll get the warning that branches have diverged. Of course, you won’t get this warning if you have disabled synchronous branch control.

Rollback

There is one more nice feature for synchronous branch management. If you decided to checkout a branch on several roots, and checkout failed for some of them, but has already succeeded for others, you’re in the situation when branches diverge: for example, you are on master in one repository and on feature branch in the other.

To prevent this, the IDE offers to rollback successful checkout. Rollback checkout means just checkout back to the previous branch.

Rollback is offered for checkout, merge and other branch actions.

That’s all about Git branches for today.

We are looking forward for your feedback about the Git branch control interface in IntelliJ IDEA. Your suggestions are welcome. Please submit bug reports directly to our issue tracker.

This entry was posted in New Features and tagged , , . Bookmark the permalink.

11 Responses to Git Branches for Multi-root Projects

  1. Geoffrey De Smet says:

    Very nice, this feature will make me more efficient.
    Will this issue also fix the issue that “Open Github URL in browser” of a selected file does not work for multi-root git projects ( http://youtrack.jetbrains.com/issue/IDEA-67488 )?

  2. Kirill Likhodedov says:

    @Geoffrey
    Unfortunately, this is a separate issue, it will be fixed later.

  3. Gordon Tyler says:

    Synchronous branch control is great! I was wishing for something like that just the other day. :)

  4. Xav says:

    Will this feature be available for Mercurial also ?

  5. Kirill Likhodedov says:

    @Xav
    We plan to implement a similar interface for Mercurial, but not immediately.

  6. Xav says:

    @Kirill
    It is planned for 12 ?

  7. Kirill Likhodedov says:

    @Xav
    No, unfortunately, such interface for Mercurial is not planned for IntelliJ IDEA 12.

  8. Peter K says:

    Is it possible to save this flag to default to ON when all the repositories are initially checked out from master ??

  9. Kirill Likhodedov says:

    @Peter K
    This is already done. If you haven’t touched the flag manually, when you invoke Git | Branches the first time, it analyzes current branches of your repositories and sets itself to ON, if they all are on the same branch.

  10. Nishant says:

    Is this feature available on webstorm?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>