Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconsider the use of -B for the git checkout of remote branches #1368

Open
jtpio opened this issue Oct 25, 2024 · 2 comments
Open

Reconsider the use of -B for the git checkout of remote branches #1368

jtpio opened this issue Oct 25, 2024 · 2 comments
Milestone

Comments

@jtpio
Copy link
Member

jtpio commented Oct 25, 2024

As noticed in #1352, the git checkout command run when clicking on a remote branch uses the -B flag, which can be quite disruptive as it implies forcing the switch to the branch: https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt--Bltnew-branchgt

cmd = ["git", "checkout", "-B", local_branchname, branchname]

For now this was mitigated in #1366 with the addition of a confirmation dialog, to warn users of potential data loss.

It could however be interesting to still be able to check out remote branches via the UI, and be able to switch back to a local branch, without losing data, and similar to the workflow available via the git command directly.

@jtpio jtpio changed the title Reconsider the use of -B for the git checkout or remote branches Reconsider the use of -B for the git checkout of remote branches Oct 25, 2024
@jtpio jtpio added this to the Future milestone Oct 25, 2024
@gjmooney
Copy link
Contributor

Playing around with this, modifying https://github.com/jupyterlab/jupyterlab-git/blob/main/jupyterlab_git/git.py#L1128 to be a normal git checkout <branch_name> for remote branches works the same as using the command line, the UI reflects being in a detached head state, and switching back to the local branch retains any changes as you would expect.

@jtpio
Copy link
Member Author

jtpio commented Oct 28, 2024

For reference, this -B option was added in #1066 to fix #741.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants