Bryan Anderson
Bryan Anderson

Reputation: 275

Git graph not showing branch

How come when I create a new branch and make commits to it I am not seeing it branch off in my graph.

Here is the code i am doing:

git init

git add .
git commit -a

... other commits in here

git checkout -b mynewbranch

git add .
git commit -a

git checkout master
git merge mynewbranch

git add .
git commit -a

This is what I expect to see in my mind when I perform git log --graph

* 47926e1 This is a commit back on master
 \
  * f3dc827 How come i am not seeing a branch in my tree
  * 1cd3018 This should be on my new branch  
 /
* 47f3716 This is my third commit
* 878b018 This is my second commit 
* 2db9f83 Initial commit 

But I am seeing this:

* 47926e1 This is a commit back on master
* f3dc827 How come i am not seeing a branch in my tree
* 1cd3018 This should be on my new branch
* 47f3716 This is my third commit
* 878b018 This is my second commit
* 2db9f83 Initial commit

Am I not understanding something?

Upvotes: 15

Views: 8551

Answers (1)

antlersoft
antlersoft

Reputation: 14786

If there are no commits to master while you are working on mynewbranch, your history will look like what you've shown. In that case, no actual merge is required; merged master is identical to the tip of mynewbranch. If this is the case, git will (by default) do what is known as a fast-forward merge; master's branch pointer is just updated to be the same commit as the tip of your merge. This usually results in a simpler commit history that is easier to work with, especially if work is also going on in remote repositories.

If you want to force the merge to be recorded as a merge in git, you can use the --no-ff option on git merge.

In git, it's generally considered good practice to avoid merges where possible.

Upvotes: 19

Related Questions