Sublime Forum

Add confirm/prompt/warning when checkout branch from HEAD state



Sometimes in projects I change the code and commit directly from the submodule. But there is a case where the changes are easy to lose.

Common scenario:

  1. Clone the project with the submodule and open it in Sublime Merge.
  2. Open a submodule from “submodules” menu.
  3. Checkout the branch.
    change content in the submodule
  4. Stage, commit, push

If you forget step 3, the last commit will be in HEAD state, with no relation to branch. If I checkout the branch, Sublime Merge will just delete the local commit without any prompts or warnings. It is my wrong steps, because I can, for example, reset (mixed) to the last commit in a branch and re-commit the changes, but it seems too easy to lose commits and changes.

I fell into this trap 2 times already :frowning:



I haven’t used submodules yet myself, but this sounds a lot like this:



The ref log can be your friend here. Commits are never deleted in git and ‘resurrection’ of lost commits is possible.

1 Like


I added a command that I called “Set branch to head” to deal with this situation. When I find myself in the situation that I did a commit without having checked out a branch, this command allows me to pick a local branch to set to the HEAD at which I’m at without leaving the commit. In the Default.sublime-commands I added the following command:

“caption”: “• Set branch to head”,
“command”: “git”,
“args”: { “argv”: [“checkout”, “-B”, “$select_local_branch”] }

Note: This is sets the branch to the current commit and does not care if the branch was in the commits ancestors or in a parallel branch.

Hope this helps!



You can also use the Create Branch command if there is no applicable branch.