WebStorm 2020.1 Help

Manage Git branches

In Git, branching is a powerful mechanism that allows you to diverge from the main development line, for example, when you need to work on a feature, or freeze a certain state of a code base for a release, and so on.

In WebStorm, all operations with branches are performed in the Git Branches popup. To invoke it, click the Git widget in the Status bar:

Git widget

The widget shows the name of the branch that is currently checked out.

Mark branches as favorites

If you have many branches, you may want to see only your favorite ones. The master branch is marked as a favorite by default. Favorite branches are always displayed at the top of the Branches popup.

  • To mark a branch as a favorite, hover the mouse cursor over the branch name, and click the star outline that appears on the left:

    favourite branch
  • To hide non-favorite branches, click Show Only Favorites at the bottom of the Branches popup.

Create a new branch from current branch

  1. In the Branches popup, choose New Branch.

  2. In the dialog that opens, specify the branch name, and make sure the Checkout branch option is selected if you want to switch to that branch.

    The new branch will start from the current HEAD. If you want to start a branch from a previous commit instead of the current branch HEAD, select this commit in the Log tab of the Version Control tool window Alt+9 and choose New Branch from the context menu.

Create a new branch from selected branch

  1. In the Branches popup select a local or a remote branch that you want to start a new branch from and choose New Branch from Selected from the list of actions.

  2. In the dialog that opens, specify the branch name, and make sure the Checkout branch option is selected if you want to switch to that branch.

Checkout a branch as a new local branch

If you want to work on a branch created by someone else, you need to check it out to create a local copy of that branch.

To make sure you have a full list of remote branches, click Fetch icons actions refresh in the branches popup:

the Fetch icon
  1. In the Branches popup, select a branch that you want to check out locally from Remote Branches, or Common Remote Branches if your project has several roots and synchronous branch control is enabled, or from Repositories | Remote Branches if it is disabled.

  2. Choose Checkout from the list of actions.

  3. Enter a new name for this branch if necessary, or leave the default name that corresponds to the remote branch, and click OK.

    The new local branch will be set to track the origin remote branch.

Switch between branches

When multitasking, you often need to jump between branches to commit unrelated changes.

  1. In the Branches popup, select the branch that you want to switch to under Local Branches and choose Checkout from the list of available operations.

  2. What happens next depends on whether there are conflicts between your local changes that you have not committed yet, and the branch that you are going to check out:

    • If your working tree is clean (that means you have no uncommitted changes), or your local changes do not conflict with the specified branch, this branch will be checked out (a notification will pop up in the bottom-right corner of the WebStorm window).

    • If your local changes are going to be overwritten by checkout, WebStorm displays a list of files that prevent you from checking out the selected branch, and suggests choosing between Force Checkout and Smart Checkout.

      If you click Force Checkout, your local uncommitted changes will be overwritten, and you will lose them.

      If you click Smart Checkout, WebStorm will shelve uncommitted changes, check out the selected branch, and then unshelve the changes. If a conflict occurs during the unshelve operation, you will be prompted to merge the changes. For details, see Resolve conflicts.

Compare branches

If you want to check how two branches have diverged from each other, you can compare them.

  • From the Branches popup, select the branch that you want to compare with the current branch, and choose Compare with Current.

  • To see a list of commits that exist in one branch and do not exist in the other, explore the Log tab in the dialog that opens.

  • To see a list of all files that are different in the two branches, switch to the Files tab.

    You can click the Swap branches link to toggle which branch is considered as a base against which you are comparing the other branch. The base branch is displayed on the left.

After you have integrated the changes from a feature branch into the main line of development, you can delete the branch you do not need anymore.

Delete branches

  1. Ensure that you have checked out a branch for your further development.

  2. Invoke the branches popup and select the branch you want to delete.

  3. Choose Delete from the submenu.

After you have deleted a branch, a notification will be displayed in the bottom-right corner from which you can restore the deleted branch:

deleted branch notification

If the branch contained commits that have not yet been merged to its upstream branch or to the current branch, it will still be deleted immediately (equivalent to the git branch --D or git branch --delete --force command), but the notification will also contain a link allowing you to view the unmerged commits.

If the deleted branch was tracking a remote branch, there will also be a link in this notification to remove the remote branch.

Configure synchronous branch control for multi-rooted repositories

If you have a multi-rooted repository, you can configure WebStorm to perform all branch operations (such as checkout, merge, delete, and so on) simultaneously on all roots as if it were a single repository. If an operation fails at least in one of the repositories, WebStorm prevents branches from diverging by suggesting you to roll back this operation in the repositories where it was successful.

  1. In the Settings/Preferences dialog Ctrl+Alt+S select Version Control | Git.

  2. Select the Execute branch operations on all roots option (note that this option is only available if your project has multiple roots).

Last modified: 13 May 2020