Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging branches with Git in IntelliJ IDE

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?

like image 894
THE JOATMON Avatar asked May 01 '17 15:05

THE JOATMON


People also ask

How do I merge branches in Git?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch.


2 Answers

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

like image 73
dgraf Avatar answered Sep 21 '22 07:09

dgraf


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.

like image 32
Tim Biegeleisen Avatar answered Sep 17 '22 07:09

Tim Biegeleisen