Fork me on GitHub
#emacs
<
2022-03-28
>
Quest17:03:44

Magit specific, but can I get this error to be ignored when running magit-checkout-branch ? This is always thrown with any unstaged change, even when I'm creating a new branch from the current HEAD (which inherently can't conflict) Cannot checkout when there are uncommitted changes Is there a better way to do this? This is one of the last uses that I still have for git CLI over magit; faster to run git checkout -b than 2x magit-stash + magit-checkout-branch .

pavlosmelissinos17:03:03

Do you mean magit-branch-checkout? Either way, I don't get that error (with magit 3.3.0), even when I have tracked changes, so maybe it's on your end? :thinking_face: Can you share your magit config and version? (Btw aren't you running magit commands from the magit-status buffer? Even if you had to do "2x magit-stash + magit-checkout-branch" you'd only have to write z z b c <name of branch> z p which is - probably- still easier to type than git checkout -b)

1
Andrea17:03:56

you could advice that function to stash for you, no? If you are not familiar with advicing functions, you can add something like

(advice-add 'magit-checkout-branch :before
              (lambda (&rest _)
                (shell-command "git stash;"))

Quest23:03:42

Hmm, making the function stash for me might work. But it's odd that it doesn't repro. I'll experiment tomorrow and see if I can figure out what's causing this