Ensuring Correct Remote is Used for Git Branch Push in Worktree Setup
Hi,
I use Git work trees concept and have a base repository with two remotes: base_repo
and repo_1
. I opened the repo_1
project and created a new branch under repo_1/DEV
(a remote tracking branch) via IntelliJ. To do this, I selected the branch, right-clicked, and chose "New branch from remote name/branch name" from the context menu. A dialog popped up asking for the new branch name, titled "Create branch from repo_1/DEV," which is correct.
After checking out, I made a few commits. When pushing, I expected that since the remote tracking branch was not set for the local branch, it would create a new remote branch with the name of the current local branch and then push the commits. However, when I tried to push, the default remote was set to base_repo
instead of repo_1
, despite the branch being created from repo_1
. It's inconvenient to manually change the remote every time I push.
Is there a solution to ensure the correct remote (repo_1
) is used by default when pushing a branch created from that remote? If yes, please let me know.
Note: This issue is not observed in a regular Git setup.
Thank you!
Please sign in to leave a comment.
Hi,
How do you open the project exactly?
Which remote does the work tree copy have listed under “Manage remotes” (double shift, search)
There should be no difference between opening a regular project and a worktree copy.
Hi,
I opened the project in the usual way—nothing special.
In the worktree copy, under "Manage remotes", all the remotes from the parent repository are listed.
I hope my explanation above is clear. I also tested this on a smaller repo and was able to reproduce the issue. If the steps are unclear, please let me know.
When I tested this on smaller data, I realized we don’t even need a worktree. The issue is reproducible without it. Please find the updated steps below:
Steps to Reproduce:
Observed Issue:
When pushing, you’ll notice a mismatch in the remote name.
I’m not sure if this behavior existed before, but if there’s an issue in my steps, please let me know.
Please note: This issue occurs only once, as the newly created branch doesn’t have a tracking branch set initially. Once a tracking branch is set, this issue no longer occurs.
However, I create branches this way to avoid the manual steps of creating a remote branch, fetching it, and then setting it to a local branch. Using this option, the remote branch will be created automatically under the specified remote (inherited from the parent branch where it was created) and set as the tracking branch for the local branch. Unfortunately, this is not happening, and that’s the problem.
Thank you!
Hi,
You are correct, please see: https://youtrack.jetbrains.com/issue/IJPL-84773/Analog-for-git-checkout-b-new-branch-origin-master
Feel free to comment and vote. Thank you.
Hi,
I didn’t understand what you meant. Are you saying there is already a tracker for this issue, or is this an FAD?
Thank you!
Hi,
Yes, the issue is already opened. Please feel free to vote it up! Thanks.