Let's go step by step comparing the 2 code blocks. Block №1:
git checkout develop
git branch test/udp_client
git checkout test/udp_client
What it does: it checks out (or create from remote) branch develop
. It creates a new branch test/udp_client
(but not develop/test/udp_client
; the name of the current branch is not used in creating a new branch) pointing to the same commit as the current branch (the current is develop
). Then it checks out the new branch. The last 2 commands in the block can be combined into one command: git checkout -b test/udp_client
. Branch develop
is not required to be the currently checked out branch — the command git checkout -b test/udp_client develop
creates a new branch pointing to the same commit as develop
and checks out the new branch; so the command replaces all 3.
The second block
git branch develop/test/udp_client
git checkout develop/test/udp_client
is very similar. If we ignore the existence of branch develop
in the repository what the block does is: it creates a new branch develop/test/udp_client
pointing to the same commit as the current branch; the current branch is not necessary develop
, it's most probably main
or master
. Then the code checks out the new branch.
Unfortunately there is already branch develop
so the 2nd block fails with cryptic error message "fatal: Failed to lock ref for update: Not a directory" or "fatal: Failed to lock ref develop/test/udp_client for update: branch develop already exists". The problem is slashes are used in branch names exactly as path separators: branches are stored as files and branches with slashes are stored as directories with the leaf (last path component) as a file. You cannot have develop
both as a directory and a file at the same time. I.e., if you have branch develop
you cannot create develop/test/udp_client
and vice versa — if you have branch develop/test/udp_client
you cannot create branch develop
.
I cannot answer Question B as I don't use worktrees — I use a lot of submodules and worktrees are incompatible with submodules so I just use separate clones.