Today, in this tutorial, we will introduce the highly practical branch management features in IntelliJ IDEA.
When using version control tools like Git, we often create different branches to develop new features. IntelliJ IDEA provides a convenient interface for creating, switching, and deleting these branches. With a simple and intuitive interface, developers can easily switch between different features, experiments, or bug fixes without worrying about interfering with other parts of the code.
This article will comprehensively explain how to use these branch operations in IntelliJ IDEA. Whether you are a beginner or an experienced developer, these features will make your workflow smoother.
Creating Git Branches in IntelliJ IDEA
Step 1 | Open the “Create New Branch” Window
In the top-left corner of the workspace’s user interface, there is a dropdown menu for Git branches. Let’s click on it with the left mouse button to expand it. Next, we select “New Branch…” (If you are using a Windows system, you can also open it directly in the workspace by pressing Ctrl+Alt+N.)

Step 2 | Create a New Branch
First, enter the desired branch name in the “New branch name” field. Typically, to distinguish between different branch purposes, we use prefixes like “feature” or “bug” to differentiate feature and bug branches. However, different project teams may have different naming conventions, so please follow your team’s guidelines for naming.
Once the name is entered, we can see at the bottom-left of the window an option labeled “Checkout branch,” which means whether we want to switch the workspace to the newly created branch after its creation. In our day-to-day development work, we usually check this option. After all, the purpose of creating a new branch is to avoid affecting the original normal branch, right?
After completing the settings, we click on the “Create” button to create the new branch.

Additionally, here’s a brief supplementary explanation. In the bottom-right corner of the window, there is an option called “Overwrite existing branch,” which will appear if the newly set branch name already exists. Once checked, the new branch will directly overwrite the old branch, so please be cautious when using this option. Typically, we can also use the availability of this option to determine whether there is an existing branch with the same name. If there is, we usually choose a different name for the new branch.

Step 3 | Switch to the New Branch
Since we just checked the option to automatically switch, the system will automatically switch to the new branch after creating it. At this point, a prompt message will appear in the bottom-left corner of the workspace.

Furthermore, the Git branch dropdown menu in the top-left corner has also been updated with the name of our new branch. So, at this point, we can be certain that our workspace is now operating under the new branch. From here on, all commit operations will be made to the new branch, and they will not affect the original branch.

Pushing Local Git Branch to Remote Repository in IntelliJ IDEA
Step 1 | Open the Push Dialog
First, hover the mouse over the Git branch dropdown menu in the top-left corner of the workspace, and after clicking to expand it, you can find “Push…” option below.

Step 2 | Verify the Information of Local Branch and Remote Repository
After clicking, the “Push Commit” dialog will appear as shown below. In this dialog, we can see the “→” symbol, where on the left is the name of the local branch, and on the right is the destination information for the remote repository. Sequentially, we can observe the remote repository’s code, the corresponding remote repository branch name, and whether this branch is a new branch for the remote repository. Once we have verified everything is correct, we can press the “Push” button to push the branch to the remote repository.

Step 3 | Verify if the New Branch has been Pushed to the Remote Repository
After the push is completed, you can see the notification of the successful push in the bottom-right corner of the workspace, as shown in the following image.

Next, we open the GitHub interface and click on “branches.”

At this point, we can confirm that the new branch has been successfully created.

Switching Git Branches in IntelliJ IDEA
First, hover the mouse over the Git branch dropdown menu in the top-left corner of the workspace, and after clicking to expand it, you can find the list of currently available local and remote branches in the “Local” or “Remote” section. Move the mouse cursor to the branch name you want to switch to and click to open the advanced branch selection menu.

In the advanced branch selection menu, click on “Checkout.” After that, you will see a prompt message indicating the branch switch, and the Git branch dropdown menu in the top-left corner will also change to display the name of the new branch.

(It’s worth mentioning that if you are switching to a branch that exists remotely but does not exist locally, IntelliJ IDEA will automatically create a local branch with the same name.)
Deleting Git Branches in IntelliJ IDEA
First, hover the mouse over the Git branch dropdown menu in the top-left corner of the workspace, and after clicking to expand it, you can find the list of currently available local and remote branches in the “Local” and “Remote” sections. Move the mouse cursor to the branch name you want to delete and click to open the advanced branch selection menu.

In the advanced branch selection menu, click on “Delete.”

After that, you will see a notification message in the bottom-right corner of the workspace indicating the successful deletion of the branch. At this point, the branch has been deleted.

Some of you may have noticed that there is a “Restore” option in the notification message. If you accidentally deleted the branch, you can quickly press this option to have the system restore the branch you just deleted. Having this mechanism is really reassuring, as it provides a chance for those who might make mistakes to recover their work.
Summary
In this tutorial, we covered some essential Git branch operations in IntelliJ IDEA. We learned how to create a new branch, push a local branch to a remote repository, switch between branches, and delete branches. IntelliJ IDEA’s user-friendly interface makes these tasks straightforward and helps developers manage their code more efficiently. Mastering these branch operations can significantly enhance your version control workflow and collaboration within your development team.




