Git branch is still on same line as master
Asked Answered
T

2

9

I am getting something unexpected happening in the git tree. I have created a branch off of master, however while I am performing commits on the new branch it appears as though these are taking place in the same code line as master...

enter image description here

enter image description here

As you can see, on the very left hand side is the code line for master (dark blue) and right at the top we can see Sprint_15 which is a branch taken from master that appears to have commits on the same line... I am not sure why this is taking place. I would expect to see the code diverge into a new line since features are being merged into Sprint_15 and not master...

My thought is that by merging Sprint_14 and Sprint_15 together this has done something funky to the history but I am not sure why.

I am still fairly new to git so some of its underpinnings still confuse me.

Theatricalize answered 5/6, 2017 at 5:34 Comment(0)
S
15

It seems that you are a bit mistaken on how git works (which is normal because you said you are new to git)

Each branch does not necessarily get it's own line. If your branch Sprint_15 has it's base as master and Sprint_15 is any number of commits ahead of master then they will share the same line. As soon as master gets a new commit then I think you will see what you expect.

You can test this in a separate git repo like this.

$ mkdir testing && cd testing
$ git init  # should put you on master branch by default
$ touch testFile.txt
$ git add -A
$ git commit -m "initial commit"
$ git branch newBranch
$ git checkout newBranch # switch from master to newBranch

### modify the testFile.txt in some way and then...
$ git add -A
$ git commit -m "first commit on newBranch"

Now if you use the same tool to look at your repo, you should see only a single line, like this: same line

Now go back to the master branch and make another commit:

$ git checkout master
### make another change to testFile.txt
$ git add -A
$ git commit -m "second commit on master"

Now you will see each branch having it's own line like you were expecting, like this:enter image description here

Scottie answered 5/6, 2017 at 6:5 Comment(3)
this seems like the correct answer, thanks for the explanation!Theatricalize
I'm curious, is there any way to force Git (or GUI tool) to display the new-branch (instead of master) as a straight line? Because sometimes I want to see entire tree but keep a specific branch as my "line of interest" around which everything else should be split off.Silicon
@Silicon I think it will depend on the GUI tool you use. In SourceTree instead of displaying All Branches you can select Current Branch. GitKraken has something similar which they call Soloing a branch. Maybe this will be close to what you are looking for.Scottie
D
0

This is a speculation, but I suggest that the reason your current feature branch appears to be on the same line as master is because currently that branch is directly ahead of master by some number of commits. To test this, try doing a pull on the latest master branch. If this changes your configuration such that Sprint_15 appears as a separate line, then my hunch was correct.

In any case, you can always check such things directly from the Git bash if you are in doubt.

Dasha answered 5/6, 2017 at 5:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.