I use the feature/fix/chore convention for structuring my branches on my repos. When trying to use git worktree I have a problem on which if I add a worktree like this:
git worktree add feature/feature_1
What it will do is create create a new branch called feature_1 and place it under a foler name feature, instead of checking out my already existing remote branch called feature/feature_1.
Then when I try to do a git push I get the following error: "fatal: the current branch feature_1 has no upstream branch".
When I check the mapping of the branches using git remote show origin I see the message:
Local branch configured for 'git pull':
feature/feature_1 merges with remote feature/feature_1
So, in theory things are set up as expected, but don't work out.
I tried using git config --global push.autoSetupRemote true it will create a new feature_1 branch, located outside my feature folder on the remote repo.
Any pointers how I can get this to work?
Note the usage of
git worktree:Without the [<commit-ish>] optional arg, it implies a branch name from what is a path name.
To get what you want, ie avoid the inference of a branch name, you must give both path and commit-ish explicitly:
In this case, the first
feature/feature_1is strictly a pathname, not used to derived a branch name, and the secondfeature/feature_1is the branch to be checked out at that path.In any case, realistically the path name would be something like
~/proj/feature_1, ie a path outside of the CWD repo, or you'll end up with a worktree-inside-a-worktree, which is not invalid, but might be confusing to yourself, especially because you can end up with worktree-inside-a-worktree-inside-a-worktree-turtles-all-the-way-down.