Merging branches with Git in IntelliJ IDE

29,227

Solution 1

The standard workflow you are following goes something like this:

git checkout InlineEditing
# work work work
git commit -m 'finished my work'

# now switch to master and merge the feature branch into it
git checkout master
git merge InlineEditing
# resolve any merge conflicts; IntelliJ is great for this step

It might be slightly counterintuitive that you have to switch to master in order to merge another branch into it. Instead, you might have expected to be able to merge InlineEditing into master from the former branch. This is just how Git works.

With regard to your original question about IntelliJ, I think there is nothing wrong with using a GUI tool for Git, provided that you know what you are doing. I tend to do most Git operations from the command line, because I am experienced doing this and the command line is powerful. But there are many cases where I use tools like IntelliJ. For example, resolving merge conflicts is much easier in IntelliJ than the command line. Also, visualizing the history of a branch can be easier using a GUI tool.

Solution 2

You normally have two merge use cases.

  1. First use case is as you have already described: there are no changes in the master branch. In this case the merge is pretty easy, see the steps on the picture below.

scenario_1

  1. Second use case is a bit complicated: there are some changes in the master branch. You want first update the master and the InlineEdit and then merge InlineEdit into master. See the steps on the picture below.

scenario_2

Share:
29,227
THE JOATMON
Author by

THE JOATMON

Hobbies include off-roading, gaming, reading and infuriating SO users by attempting to write code myself. "I must create a system, or be enslaved by another man's; I will not reason and compare: my business is to create." - William Blake

Updated on July 19, 2022

Comments

  • THE JOATMON
    THE JOATMON almost 2 years

    I know there are dozens of questions on this, but I'm having trouble. First off, I'm using Webstorm (IntelliJ) not the command line. Second, this seems to vary by perspective.

    I have my master branch, obviously. I created a new branch called "InlineEditing". I've been working in this branch for a couple days. There have been no changes to the master branch. I now want to move all the changes in the current branch back to the master and resume working from there.

    In Webstorm, with InlineEditing as the current branch, I tried merging using the following method but it doesn't seem to do anything. Ie, when I then checkout the master branch, it's the old code.

    enter image description here

    So my question is, what is the proper way to "merge" my current branch back to the master?