Challenge - 5 Problems
Branch Recovery Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Recovering a recently deleted branch
You accidentally deleted a branch named
feature-x. Which command will correctly restore it if the branch was deleted very recently and you know the branch's last commit is still in the reflog?Attempts:
2 left
💡 Hint
Use
git reflog show feature-x to access the branch-specific reflog and extract the most recent commit hash.✗ Incorrect
The command
git reflog show feature-x -1 displays the most recent entry in the reflog for the feature-x branch reference, even after deletion. The first field is the commit hash of the branch tip. awk '{print $1}' extracts it, and git checkout -b recreates the branch at that commit.🧠 Conceptual
intermediate1:30remaining
Understanding reflog for branch recovery
What does the
git reflog command track that makes it useful for recovering deleted branches?Attempts:
2 left
💡 Hint
Think about what information helps find lost commits or branches.
✗ Incorrect
git reflog records every change to HEAD and branch tips, including commits, checkouts, resets, and merges. This history allows you to find commits even if branches are deleted.❓ Troubleshoot
advanced2:30remaining
Recovering a deleted branch when reflog is cleared
You deleted a branch
bugfix and also ran git reflog expire --expire=now --all which cleared the reflog. What is the most reliable way to recover the branch now?Attempts:
2 left
💡 Hint
Think about how to find commits not referenced by any branch or reflog.
✗ Incorrect
git fsck --lost-found finds dangling commits that are not referenced by any branch or reflog. You can identify the commit for the deleted branch and recreate it. Other options either rely on remote branches or do not restore the commit.🔀 Workflow
advanced3:00remaining
Steps to recover a deleted branch safely
Which sequence of commands correctly recovers a deleted branch
release using reflog and then pushes it back to the remote repository?Attempts:
2 left
💡 Hint
First find the commit, then create the branch, verify, and finally push.
✗ Incorrect
First, use
git reflog to find the commit hash. Then create the branch at that commit with git checkout -b release <commit-hash>. Next, verify the branch history with git log --oneline -5. Finally, push the recovered branch to the remote with git push origin release.✅ Best Practice
expert2:00remaining
Preventing branch loss in collaborative projects
What is the best practice to avoid losing important branches accidentally in a shared Git repository?
Attempts:
2 left
💡 Hint
Think about collaboration and safety features in Git hosting services.
✗ Incorrect
Pushing branches to remote ensures they are backed up. Branch protection rules prevent accidental deletion or force pushes on important branches. This practice helps teams avoid losing work.