Due to the use of submodules in my projects I'm finding myself often on "(no branch)". As I'm also adding code to those submodules I'm committing in there. When I then want to push those submodules I need to be on a branch of course. Hence my question:
Is there a way/shortcut in git (command line) to set a local branch to the current commit/HEAD without the detour of
git checkout the_branch
git reset --hard <previous commit-ish>
git branch -f
Checkout the branch with
-B: this will reset the branch to HEAD, which is the current ref.
git checkout -B <branch>
From the docs:
If -B is given, is created if it doesn’t exist; otherwise, it is reset. This is the transactional equivalent of
$ git branch -f <branch> [<start point>] $ git checkout <branch>
that is to say, the branch is not reset/created unless "git checkout" is successful.