Config & Hooks Questions with Answers

9 practice questions on Config & Hooks (Git & DevOps) with answers and step-by-step solutions. Try 9 samples below, then practise all 9 free in the AptiNest app.

Sample questions

Question 1Easy

What exit code does git config --get some.missing.key return when the key is not set?

  1. 0
  2. 128
  3. 2
  4. 1

Answer: D. 1

Explanation

git config --get exits with 1 when the key has no value, and prints nothing. Scripts can use that exit status to test whether a key is set.

Step-by-step solution

  1. The key some.missing.key is not set anywhere.
  2. git config --get reports a missing key with exit code 1.
  3. It prints nothing, so scripts can check the exit status.

Why the other options are wrong

  • A. 0 means success, which would mean the key has a value.
  • B. 128 is for fatal errors, such as running outside a repository.
  • C. A missing key gives 1, not 2.

Tip: Exit 1 = key not set.

Question 2Easy

A repo's .git/config sets user.name to "Local Name", and ~/.gitconfig sets it to "Global Name". Which name is used for commits in that repo?

  1. Local Name
  2. Global Name
  3. The commit fails with an error
  4. Both names are joined together

Answer: A. Local Name

Explanation

Git reads system, global and then local config, and later files override earlier ones for the same key. Local is the most specific, so Local Name wins inside the repo.

Step-by-step solution

  1. Git reads the system, global and then local config, in that order.
  2. A later value for the same key replaces the earlier one.
  3. So inside this repo, user.name is Local Name.

Why the other options are wrong

  • B. Local overrides global for the same key.
  • C. Both values are valid; git uses the more specific one.
  • D. user.name holds one value, and the later one replaces the earlier.

Tip: Most specific config wins: local over global over system.

Question 3Medium

Which git commit flag skips the pre-commit and commit-msg hooks for one commit?

  1. --skip-hooks
  2. --no-verify
  3. --force
  4. --amend

Answer: B. --no-verify

Explanation

--no-verify (short form -n) bypasses the pre-commit and commit-msg hooks for that commit. Use it sparingly, since it also skips the checks those hooks were added for.

Step-by-step solution

  1. A failing pre-commit hook normally stops the commit.
  2. --no-verify skips the pre-commit and commit-msg hooks for that commit.
  3. The commit is then created even though the hook would have failed.

Why the other options are wrong

  • A. Not a git commit option.
  • C. git commit has no --force option; --force belongs to push.
  • D. --amend replaces the last commit; it does not skip hooks.

Tip: --no-verify = skip the commit hooks.

Question 4Medium

Why are .git/hooks scripts not shared when someone clones the repo?

  1. The .git directory is not part of the versioned content
  2. Hooks are encrypted by Git and cannot be read after the clone
  3. GitHub removes them
  4. Clone strips executable files

Answer: A. The .git directory is not part of the versioned content

Explanation

Teams share hooks via a tracked folder plus core.hooksPath or tools like Husky.

Step-by-step solution

  1. Hooks live in .git.
  2. .git is not tracked.
  3. Use core.hooksPath to share.

Why the other options are wrong

  • B. They are plain files.
  • C. Not the cause.
  • D. Not true.

Question 5Medium

Where are Git hook scripts stored by default, and what must hold true to run them?

  1. In the project root folder, with any file name and any extension
  2. In ~/.gitconfig
  3. In .git/hooks, and the file must be executable
  4. In the remote repository only

Answer: C. In .git/hooks, and the file must be executable

Explanation

Hooks like pre-commit are local scripts. The file needs the exact hook name and execute permission.

Step-by-step solution

  1. Create .git/hooks/pre-commit.
  2. chmod +x it.
  3. Git runs it at that event.

Why the other options are wrong

  • A. Hooks live inside .git.
  • B. Config does not hold scripts.
  • D. They run locally.

Question 6Medium

A team runs git config core.hooksPath .githooks. Where does Git now look for hook scripts?

  1. .git/hooks
  2. hooks/ at the repo root
  3. .githooks in the repository
  4. ~/.githooks in the home directory

Answer: C. .githooks in the repository

Explanation

core.hooksPath replaces the default .git/hooks folder. Git runs the executable hook scripts found in the folder you set, so a committed folder can share hooks with the whole team.

Step-by-step solution

  1. The default hook folder is .git/hooks.
  2. core.hooksPath overrides it with .githooks.
  3. Git runs executable scripts in .githooks, such as pre-commit.

Why the other options are wrong

  • A. That is the default, which core.hooksPath replaces.
  • B. No folder by that name is used; the setting names .githooks.
  • D. The path is relative to the repository, not the home directory.

Tip: hooksPath moves hooks into a committed folder.

Question 7Medium

A pre-commit hook exits with status 1. What happens?

  1. The commit proceeds with a warning
  2. The commit is aborted
  3. The last commit is amended
  4. A branch is created

Answer: B. The commit is aborted

Explanation

A non-zero exit from pre-commit stops the commit. --no-verify bypasses it.

Step-by-step solution

  1. The hook runs before the commit.
  2. Non-zero means failure.
  3. Git cancels the commit.

Why the other options are wrong

  • A. Only some hooks ignore failure.
  • C. No amend happens.
  • D. No branch.

Question 8Hard

In a commit-msg hook, what does the first argument ($1) contain?

  1. The commit message text itself
  2. The SHA of the commit being made
  3. The name of the current branch
  4. The path to a file that holds the commit message

Answer: D. The path to a file that holds the commit message

Explanation

Git passes the path to the message file, usually .git/COMMIT_EDITMSG. The hook can read or edit that file, and a non-zero exit status stops the commit.

Step-by-step solution

  1. git commit writes the message to a file before the hook runs.
  2. The hook receives that file's path as $1.
  3. The hook reads the text from the file; a non-zero exit stops the commit.

Why the other options are wrong

  • A. The argument is a path, so the hook must open the file to read the text.
  • B. The SHA does not exist until after the hook has run.
  • C. The branch is not passed to commit-msg; the file path is.

Tip: commit-msg gets a file path, not the message.

Question 9Hard

What does git bisect need to find a bug-introducing commit?

  1. One known good commit and one known bad commit
  2. A list of authors
  3. The remote URL
  4. Two branches

Answer: A. One known good commit and one known bad commit

Explanation

Bisect does a binary search between good and bad, testing the midpoint. git bisect run <script> automates it.

Step-by-step solution

  1. Mark bad and good.
  2. Git checks out the middle.
  3. Repeat; log2 n steps.

Why the other options are wrong

  • B. Authors are not needed.
  • C. Local only.
  • D. Commits, not branches.

Practise all 9 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Git & DevOps topics · All topics