0
0
Gitdevops~5 mins

Detached HEAD state in Git - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the Detached HEAD state in Git?
It means you are not on any branch but on a specific commit. Changes made here won't update any branch until you create one or move a branch pointer.
Click to reveal answer
beginner
How do you enter Detached HEAD state?
By checking out a commit directly using its hash or a tag instead of a branch name.
Click to reveal answer
intermediate
What happens if you make commits in Detached HEAD state and then switch branches without saving?
Those commits can be lost because no branch points to them unless you create a new branch or tag to save them.
Click to reveal answer
beginner
How can you save work done in Detached HEAD state?
Create a new branch from the current commit using 'git switch -c ' or 'git checkout -b '.
Click to reveal answer
intermediate
Why might someone want to use Detached HEAD state?
To explore or test a past commit without affecting branches, or to build and test code at a specific point in history.
Click to reveal answer
What does Detached HEAD state mean in Git?
AYou are on the latest commit of a branch
BYou have uncommitted changes
CYou are on a specific commit, not a branch
DYou are merging two branches
How do you enter Detached HEAD state?
Agit merge <branch>
Bgit checkout <branch-name>
Cgit commit -m 'message'
Dgit checkout <commit-hash>
What happens to commits made in Detached HEAD if you switch branches without saving?
AThey are lost unless saved to a branch or tag
BThey become untracked files
CThey merge with the branch you switch to
DThey are automatically saved to the current branch
Which command saves your work from Detached HEAD state to a new branch?
Agit switch -c <branch-name>
Bgit branch -d <branch-name>
Cgit reset --hard
Dgit merge <branch-name>
Why use Detached HEAD state?
ATo permanently delete commits
BTo explore or test a past commit safely
CTo push changes to remote
DTo create a new branch automatically
Explain what Detached HEAD state is and how you can safely save work done in this state.
Think about checking out commits and branch creation.
You got /3 concepts.
    Describe a scenario where Detached HEAD state is useful and what risks it carries.
    Consider testing old commits and saving changes.
    You got /3 concepts.