git worktree add renamed remote branches

50 Views Asked by At

PROBLEM:

I used these commands to create a two new branches. New branch GTEC-426-eth was supposed to originate from feature/eth_testing while new branch GTEC-426-ksz was supposed to originate from the feature/KSZ8851SNL_testing.

git worktree add -b GTEC-426-eth ../worktrees/GTEC-426-eth feature/eth_testing
git worktree add -b GTEC-426-ksz ../worktrees/GTEC-426-ksz feature/KSZ8851SNL_testing

After changes were done on these new branches, they were pushed to the origin.

git push --set-upstream origin GTEC-426-eth
git push --set-upstream origin GTEC-426-ksz

Now I am checking the Gitlab graph and it seems that this did not add new branches but renamed the existing ones...

This is the graph from tig GIT client if I run it from the GTEC-426-ksz branch:

enter image description here

This is a graph of GTEC-426-ksz branch on Gitlab:

enter image description here

What did I do wrong?


POSSIBLE REASONS:

I read in the man git worktree about -b:

 -b <new-branch>, -B <new-branch>
           With add, create a new branch named <new-branch> starting at <commit-ish>, and check out <new-branch> into the new working tree. If <commit-ish> is omitted, it defaults to HEAD. By default, -b refuses to create a new
           branch if it already exists.  -B overrides this safeguard, resetting <new-branch> to <commit-ish>.

I am working on Windows/WSL and I suspect that because Windows has problems with normal/capital letters it might interpreted -b as -B... I have no other idea why this could otherwise happen...

1

There are 1 best solutions below

0
71GA On

I understand now. All the git graphs use horizontal space saving if possible.

Let us take a look at the Graph from GitLab from earlier:

enter image description here

Here, it really looks like branch feature/eth_testing was renamed to GTEC-426-eth but this is not the case. Branches feature/eth_testing and GTEC-426-eth really are two different branches! So a normal person like me would expect this part of graph to look like this:

enter image description here

This looks nicer, but look how much horizontal space it takes! This is why, to save horizontal space, git draws a graph in a single line and marks the end of each branch like shown in the first image. It will continue to do this until it can - until there is another commit on branch feature/eth_testing. When this happens, it will be forced to move GTEC-426-eth branch out of the way and draw a graph like this:

enter image description here

I tested this by creating additional commit on feature/eth_testing and graph really behaved like just described:

enter image description here

NOTE: I also had to use tig --all instead of simply tig to see all the branches.