Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT - branches not closing after merge

we are pretty unexperienced in using GIT. Actually we like the idea of branches ;-) But somehow all merges from one user just don't close the branch...

You can look at the image here: http://i54.tinypic.com/297i14.png

There is a grey and a blue line which just got straight forward... even after the merge... So what is he doing wrong? Any clues? I don't want imagin what happens if he creates some more branches and all of them persist in the history view even after a merge...

Thank you very much!

like image 567
Bosh Avatar asked Jul 29 '11 15:07

Bosh


People also ask

Do branches disappear after merge?

In a good workflow, the feature branch is deleted once its merged back into master. New branches should be created for each new feature(s) that you work on.

How do you abort merge branches?

You can use the git reset --merge command. You can also use the git merge --abort command. As always, make sure you have no uncommitted changes before you start a merge.

Why the branch is not fully merged?

There are times when you get an “not fully merged” error for a git branch, usually when trying to delete a local branch from your machine. It's a safe bet that something in your local branch has not actually made it to the remote repository and we should do some investigating.


3 Answers

When you do a merge, the new commit only moves forward your current branch. The branch name that pointed to the other branch is left where it was. In other words, if you have this situation:

A---B---C blue
 \
  D---E---F grey

... and do:

git checkout blue
git merge grey

You'll end up with:

A---B---C---G blue
 \         /
  D---E---F grey

If you want to remove the grey branch you can then do git branch -d grey. This won't affect the commit graph, just remove the branch - they're like labels that get moved around the commit graph.

However, if you carry on and create more commits on the grey and blue branches, those lines will continue:

A---B---C---G---H---I blue
 \         /
  D---E---F---J---K---L grey

In the image you link to, I assume that either there are further commits further above the section you've shown, or the tool you're using is just presenting the commit graph strangely.

like image 129
Mark Longair Avatar answered Nov 14 '22 03:11

Mark Longair


I am not certain what you mean by closing the branch, but I'll make a guess :)

It is still possible to use a branch even after a merge has been done. I guess this is per design and how it should be. For instance you might want to continue working with the branch even after a merge has been done, say in order to continue focusing on development in that branch. That is why it still shows up in the image you referred to.

If you don't want to do that, it is possible to delete the branch after merging, which closes it definitively by issuing the command git branch -d <branch> while being in another branch, like master. (This will only delete the branch if its latest commit has been merged with the branch you have active, so there is no risk of losing data.)

like image 32
Jimmy Stenke Avatar answered Nov 14 '22 03:11

Jimmy Stenke


Currently git requires a two step process for the merging and closing of a 'task' branch where the merge nominally indicates closure of the task and that the branch is no longer required.

It maybe that it would be a useful option for some to be able to delete a branch's refs/heads entry so closing everything in one step [make a proposal to the git list?]. However I'm sure that many workflows have instances where they want the ability to go back and tidy up some minor issue, which an early deletion would make awkward. (though it would be in the reflog for a while)

Give the user the task of creating an alias or script to combine the two actions. It will help the education all round ;-)

like image 38
Philip Oakley Avatar answered Nov 14 '22 05:11

Philip Oakley