Closed thecuvii closed 3 years ago
I can't repro. Seems works fine?
Weird. In my project, There are 'detached HEAD' problem. I'll try in other projects later. Thx.
I tried in forgit repo, there are still 'detached HEAD' problem.
@Xwil This is expected. You are already switched to that branch. The message tells you the remote branch (theoretically read-only) is not actually a normal local branch and you can run git switch -c <new-branch-name>
to create a corresponding local branch if necessary.
You will find that run git checkout origin/revert-117-master
directly have the same result:
$ git clone https://github.com/wfxr/forgit
$ cd forgit
$ git checkout origin/revert-117-master
Note: switching to 'origin/revert-117-master'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 0f3cfda Revert "Attempt to make this a fish plugin"
This message seems to appear only once (so does the forgit::checkout::branch
):
$ git checkout origin/dev
Previous HEAD position was 0f3cfda Revert "Attempt to make this a fish plugin"
HEAD is now at 29bc286 fix: improve compatibility for vim (#138)
Thanks.
What if forgit provide an option, when I try to checkout a remote branch, I can pass some arguments? like git checkout --track origin/revert-117-master
.
In my case, I want to directly checkout into a remote branch, and I do not want to type git switch -c
and branch name again.
Thank you @Xwil. I understand your needs. Unfortunately there is not an easy way to achieve this.
What if forgit provide an option, when I try to checkout a remote branch, I can pass some arguments?.
gcb
regard it's argument as the branch name for now,
https://github.com/wfxr/forgit/blob/d5e0fd86e946a3f147f21b9b7a3cef0e874ee684/forgit.plugin.zsh#L221
and the trouble is we can only checkout the same remote branch with --track
once because the corresponding local branch will be created after the first run. So an option like FORGIT_LOG_GRAPH_ENABLE
is also not applicable. And you want to temporarily checkout a remote branch that happenly has the same name as a local branch, this will also fail with --track
option.
One way I can think of is to let user decide whether or not track it after selecting a remote branch. track the remote branch when possible.
@Xwil I added the auto track logic in forgit::checkout::branch
. You can update and try it.
Works fine, very nice work, thx.
@cjappl I forgot to open a pr to implement this feature. You can look into the commit https://github.com/wfxr/forgit/commit/2db37aa4ecc94e41247a0eecb1b11896fa25cded to update the fish part when you have time.
Proposing https://github.com/wfxr/forgit/pull/163 to make everyone happy
Check list
Environment info
Problem / Steps to reproduce
Cannot checkout into remote branch