Web Development Version Control 5 — Questions and Answers
Question 1: What does `git reflog` provide that `git log` does not?
- A history of all HEAD movements, including those from resets and checkouts (Correct answer)
- A log of remote repository access events
- An annotated log with file-level changes for each commit
- A list of all branches ever created in the repository
Correct answer: A history of all HEAD movements, including those from resets and checkouts
`git reflog` records every time HEAD has moved, making it possible to recover commits lost after a reset or branch deletion.
Question 2: What is 'trunk-based development'?
- All developers commit frequently to a single main branch, with feature flags to hide incomplete work (Correct answer)
- Development happens exclusively on long-lived feature branches
- Each developer maintains their own fork of the repository
- Code is only merged to the main branch after a formal release review
Correct answer: All developers commit frequently to a single main branch, with feature flags to hide incomplete work
Trunk-based development keeps the main branch always releasable by integrating small, frequent changes directly rather than long-lived branches.
Question 3: Which command renames a local Git branch?
- git branch -m <old-name> <new-name> (Correct answer)
- git rename branch <old-name> <new-name>
- git branch --rename <new-name>
- git checkout -b <new-name> && git branch -d <old-name>
Correct answer: git branch -m <old-name> <new-name>
`git branch -m` moves/renames a branch; when two names are provided it renames the old branch to the new name.
Question 4: What is the effect of `git commit --amend`?
- Modifies the most recent commit, replacing it with a new commit that includes staged changes and/or a new message (Correct answer)
- Adds a note to the latest commit without changing it
- Squashes the last two commits into one
- Updates the commit author information for all commits
Correct answer: Modifies the most recent commit, replacing it with a new commit that includes staged changes and/or a new message
`git commit --amend` rewrites the last commit with any newly staged changes and allows editing the commit message.
Question 5: What is a 'bare' Git repository?
- A repository with no working directory, used as a central server-side repository (Correct answer)
- A newly initialized repository with zero commits
- A repository that has been stripped of all commit history
- A local repository with no remote configured
Correct answer: A repository with no working directory, used as a central server-side repository
A bare repository stores only the Git data (like the `.git` folder) with no checked-out working tree, making it ideal for remote/server use.
Question 6: In Git, what is the index (also called the staging area)?
- An intermediate area where changes are prepared before being included in a commit (Correct answer)
- A database of all file paths in the repository
- The list of remote branches tracked by the local repository
- A compressed cache of the most recent commit's snapshot
Correct answer: An intermediate area where changes are prepared before being included in a commit
The index is a staging layer between the working directory and the commit history where you curate changes with `git add`.
Question 7: What does the `--force-with-lease` flag do when pushing to a remote?
- Only force-pushes if no one else has pushed to the branch since your last fetch, preventing accidental overwrites (Correct answer)
- Forces the push regardless of any remote changes
- Locks the remote branch after pushing so others cannot push
- Pushes with elevated permissions that bypass branch protection rules
Correct answer: Only force-pushes if no one else has pushed to the branch since your last fetch, preventing accidental overwrites
`--force-with-lease` is a safer alternative to `--force` that aborts if the remote ref has been updated by someone else since you last fetched.
What does `git reflog` provide that `git log` does not?