A post-merge hook is a script that runs automatically after a successful git merge. It helps automate tasks like updating dependencies or cleaning up files.
Click to reveal answer
beginner
Where do you place the post-merge hook script in a Git repository?
You place the post-merge script inside the .git/hooks/ directory of your repository, and make sure it is executable.
Click to reveal answer
beginner
What file permissions should a post-merge hook script have?
The post-merge hook script should have executable permissions, usually set with chmod +x post-merge.
Click to reveal answer
beginner
Give an example of a simple post-merge hook script that prints a message.
A simple post-merge script in Bash:
#!/bin/sh
echo "Merge completed successfully!"
Click to reveal answer
beginner
Why use a post-merge hook instead of running commands manually after merging?
Using a post-merge hook automates repetitive tasks, reduces human error, and ensures important steps run every time a merge happens.
Click to reveal answer
What triggers the post-merge hook in Git?
AAfter pushing to remote
BBefore a git commit
CWhen cloning a repository
DAfter a successful git merge
✗ Incorrect
The post-merge hook runs automatically right after a successful git merge.
Where should the post-merge hook script be located?
AInside the .git/hooks directory
BIn the root project directory
CIn the user's home directory
DIn the remote repository
✗ Incorrect
Git looks for hook scripts inside the .git/hooks directory of the local repository.
Which command makes a post-merge hook script executable?
Achmod +x post-merge
Bgit enable post-merge
Cchmod 644 post-merge
Dgit hook activate post-merge
✗ Incorrect
You use chmod +x to give execute permission to the hook script.
What is a common use of a post-merge hook?
ATo create a new branch
BTo update dependencies after merging
CTo push changes to remote
DTo delete the repository
✗ Incorrect
A post-merge hook often runs commands like updating dependencies or rebuilding files after a merge.
Can the post-merge hook run on a remote server automatically?
AOnly if configured in the remote repo
BYes, always on remote servers
CNo, it runs only on the local machine
DOnly during git push
✗ Incorrect
Git hooks like post-merge run only on the local machine where the merge happens.
Explain what a post-merge hook is and describe a simple task it can automate.
Think about what happens right after you combine code changes.
You got /3 concepts.
Describe how to set up a post-merge hook script in a Git repository.
Focus on where the script goes and what permissions it needs.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the post-merge hook in Git?
easy
A. To create a new branch after merging
B. To prevent merges from happening
C. To delete merged branches automatically
D. To run commands automatically after a merge completes
Solution
Step 1: Understand the role of Git hooks
Git hooks are scripts that run at specific points in Git workflows to automate tasks.
Step 2: Identify the specific timing of the post-merge hook
The post-merge hook runs right after a merge finishes, allowing automation of follow-up tasks.
Final Answer:
To run commands automatically after a merge completes -> Option D
Quick Check:
post-merge hook = runs after merge [OK]
Hint: Post-merge hook runs after merge finishes [OK]
Common Mistakes:
Confusing post-merge with pre-merge hooks
Thinking it prevents merges
Assuming it creates or deletes branches
2. Which of the following is the correct way to make a post-merge hook script executable on a Unix-like system?
easy
A. chmod 777 .git/hooks/post-merge
B. chmod +x .git/hooks/post-merge
C. git hook enable post-merge
D. chmod 644 .git/hooks/post-merge
Solution
Step 1: Understand file permissions for executable scripts
To run a script as a hook, it must have executable permission, usually set with chmod +x.
Step 2: Identify the correct command
chmod +x .git/hooks/post-merge sets the executable bit without giving excessive permissions.
Final Answer:
chmod +x .git/hooks/post-merge -> Option B
Quick Check:
Make hook executable = chmod +x [OK]
Hint: Use chmod +x to make hook executable [OK]
Common Mistakes:
Using chmod 777 which is insecure
Using chmod 644 which is not executable
Trying git commands to enable hooks
3. Given this post-merge hook script saved in .git/hooks/post-merge and made executable:
#!/bin/sh
npm install
npm run build
What will happen after you run git merge feature-branch?
medium
A. The dependencies will install and the project will build automatically
B. The merge will fail because of the script
C. Nothing happens because post-merge hooks do not run automatically
D. Only npm install will run, not npm run build
Solution
Step 1: Understand what the post-merge hook script does
The script runs npm install to install dependencies, then npm run build to build the project.
Step 2: Know when the post-merge hook runs
It runs automatically after a successful merge, so both commands will execute in order.
Final Answer:
The dependencies will install and the project will build automatically -> Option A
Quick Check:
post-merge runs script after merge [OK]
Hint: Post-merge runs script commands after merge [OK]
Common Mistakes:
Thinking hooks don't run automatically
Assuming only first command runs
Believing merge fails due to hook
4. You wrote a post-merge hook script but it does not run after merging. Which of these is the most likely cause?
medium
A. The script file is not executable
B. You forgot to commit the hook script
C. The merge was done with git rebase
D. The script is saved outside the .git/hooks directory
Solution
Step 1: Check script execution permissions
If the script is not executable, Git will not run it after merge.
Step 2: Understand that hooks are local and not committed
Hooks are not shared via commits, so forgetting to commit is irrelevant.
Step 3: Consider merge method and script location
Rebase does not trigger post-merge, but the question states a merge was done. Also, hooks must be in .git/hooks.
Final Answer:
The script file is not executable -> Option A
Quick Check:
Non-executable script = hook won't run [OK]
Hint: Check if hook script has executable permission [OK]
Common Mistakes:
Thinking hooks are shared via commits
Confusing merge with rebase triggers
Saving script outside .git/hooks folder
5. You want to ensure that after every merge, your Python project automatically installs new dependencies listed in requirements.txt and runs tests. Which post-merge hook script is the best choice?
hard
A. #!/bin/sh
git pull
pytest
B. #!/bin/sh
npm install
npm test
C. #!/bin/sh
pip install -r requirements.txt
pytest
D. #!/bin/sh
pip uninstall -r requirements.txt
pytest
Solution
Step 1: Identify the correct commands for Python dependency installation and testing