0
0
Gitdevops~20 mins

How branches are just files with hashes in Git - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Branch Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What does a Git branch file contain?

In Git, branches are stored as files inside the .git/refs/heads/ directory. What is the content of these branch files?

AThe full commit history of the branch as text
BA list of all files changed in the branch
CThe branch name repeated multiple times
DThe SHA-1 hash of the latest commit the branch points to
Attempts:
2 left
💡 Hint

Think about what uniquely identifies a commit in Git.

💻 Command Output
intermediate
1:30remaining
Reading a branch file content

You run the command cat .git/refs/heads/main in your Git repository. What output do you expect?

AThe SHA-1 hash of the latest commit on main
BA list of all commits on the main branch
CThe branch name 'main'
DAn error saying the file does not exist
Attempts:
2 left
💡 Hint

Try to remember what the branch file stores inside the .git folder.

Troubleshoot
advanced
2:00remaining
Why does Git say 'fatal: not a git repository' when reading a branch file?

You try to run git rev-parse refs/heads/feature but get the error fatal: not a git repository. What is the most likely cause?

AYou are not inside a Git repository directory
BThe branch name 'feature' does not exist
CThe branch file is corrupted and unreadable
DYour Git version is outdated
Attempts:
2 left
💡 Hint

Check your current folder and if it contains a .git directory.

🔀 Workflow
advanced
2:00remaining
How to update a branch pointer manually

You want to manually update the dev branch to point to a specific commit hash abc1234. Which command correctly updates the branch file?

Aecho abc1234 > .git/refs/heads/dev
Bgit update-ref refs/heads/dev abc1234
Cgit branch dev abc1234
Dgit checkout dev && git reset --hard abc1234
Attempts:
2 left
💡 Hint

Think about the safest Git command to update branch references.

Best Practice
expert
2:30remaining
Why should you avoid manually editing branch files?

Branch files in Git are simple text files containing commit hashes. Why is it recommended to avoid manually editing these files?

AGit automatically overwrites manual changes on next commit
BManual edits are faster but less secure than Git commands
CManual edits can cause Git to lose track of commits and corrupt the repository
DManual edits are required only for advanced users
Attempts:
2 left
💡 Hint

Consider what happens if the branch points to a non-existent commit hash.