0
0
Gitdevops~20 mins

Sharing hooks with the team (husky) in Git - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Husky Hook Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of installing Husky with the correct command?
You run the command npm install husky --save-dev in your project. What is the expected output message you should see to confirm Husky installed successfully?
Ahusky is not recognized as an internal or external command
Berror: command not found: husky
Cnpm ERR! missing script: husky
Dadded 1 package, and audited 1 package in 2s
Attempts:
2 left
💡 Hint
Look for the message that confirms a package was added without errors.
🔀 Workflow
intermediate
1:30remaining
Which step correctly sets up Husky hooks to be shared with the team?
After installing Husky, which command should you run to initialize Husky hooks so they are tracked in your Git repository and shared with your team?
Anpx husky install
Bgit init
Cnpm start
Dhusky add .husky/pre-commit "npm test"
Attempts:
2 left
💡 Hint
This command creates the hooks folder and sets up Git hooks.
Configuration
advanced
2:00remaining
Which package.json script ensures Husky hooks are installed automatically after cloning?
You want Husky hooks to be installed automatically when a team member clones the repo and runs npm install. Which package.json script configuration achieves this?
A"prepare": "husky install"
B"postinstall": "husky install"
C"preinstall": "husky install"
D"install": "husky install"
Attempts:
2 left
💡 Hint
This script runs automatically after dependencies are installed and before publishing.
Troubleshoot
advanced
2:00remaining
Why does the Husky hook not run after cloning the repo?
A team member cloned the repo and ran npm install, but Husky hooks do not run on Git commits. What is the most likely cause?
AGit is not installed on the team member's machine
BThe .husky folder is ignored by .gitignore
CThe <code>prepare</code> script is missing in package.json, so hooks were not installed
DThe team member did not run <code>npx husky add</code> manually
Attempts:
2 left
💡 Hint
Check if the hooks installation step runs automatically after install.
Best Practice
expert
2:30remaining
What is the best way to share a new pre-commit hook with your team using Husky?
You want to add a new pre-commit hook that runs npm test and share it with your team. Which sequence of commands and steps is best practice?
ACreate a shell script with tests and share it via email
BRun <code>npx husky add .husky/pre-commit "npm test"</code>, commit the .husky folder, and push to the repo
CRun <code>npx husky install</code> on your machine only, no commit needed
DAdd <code>npm test</code> to package.json scripts, then tell team to run it manually
Attempts:
2 left
💡 Hint
Think about how Git tracks files and how Husky hooks are stored.