Git create branch where detached HEAD is

GitGit BranchGit Detached-Head

Git Problem Overview


I tried something like this:

git branch temp

to create a new branch but don't move the HEAD. But I get:

# Not currently on any branch.

I don't want to merge anything, I just want a new branch at the current HEAD.

Git Solutions


Solution 1 - Git

You're sitting on a detached HEAD:

git checkout <sha>

You want to make a branch at that commit:

git branch my-new-branch

And now switch to that branch:

git checkout my-new-branch

Solution 2 - Git

You can also use:

git switch -c <new branch name>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbskyView Question on Stackoverflow
Solution 1 - GitredhotvengeanceView Answer on Stackoverflow
Solution 2 - GitRoy SalazarView Answer on Stackoverflow