10 Essential Git Commands for Senior Developers Quiz

Discover key Git commands that elevate developers from basic usage to senior expertise, covering history management, bug fixing, release tasks, and safe collaboration.

  1. Using git rebase for a Clean History

    What is the main reason senior developers use 'git rebase' before raising a pull request?

    1. To push changes to the remote repository
    2. To create a new branch
    3. To keep the commit history clean and linear
    4. To save uncommitted changes

    Explanation: 'git rebase' is mainly used to keep commit history clean and avoid unnecessary merge commits. Creating a new branch is done with 'git branch', saving uncommitted changes is handled by 'git stash', and pushing changes uses 'git push'.

  2. Selective Bug Fixes with git cherry-pick

    Which Git command lets you apply a specific commit from one branch to another for selective bug fixes?

    1. git cherry-pick
    2. git revert
    3. git merge
    4. git stash

    Explanation: 'git cherry-pick' applies a specific commit to another branch, useful for selective bug fixes. 'git revert' undoes a commit, 'git stash' saves changes temporarily, and 'git merge' combines entire branch histories.

  3. Recovering Lost Commits

    Which Git command helps you recover lost commits even after running dangerous operations like 'git reset --hard'?

    1. git reflog
    2. git pull
    3. git add
    4. git log

    Explanation: 'git reflog' tracks all reference movements, letting you recover commits lost to resets. 'git log' shows history but not deleted commits, 'git pull' fetches/remotes, and 'git add' stages changes.

  4. Difference Between git reset --soft and --hard

    What is the key difference between 'git reset --soft' and 'git reset --hard'?

    1. --soft merges branches, --hard splits branches
    2. --soft pushes commits, --hard reverts them
    3. --soft keeps changes, --hard deletes changes
    4. --soft creates a new branch, --hard does not

    Explanation: '--soft' keeps your changes staged after resetting, while '--hard' permanently deletes them. The other options incorrectly describe actions unrelated to reset.

  5. Handling Urgent Tasks with git stash

    During mid-work, what Git command allows you to quickly save uncommitted changes to handle an urgent production bug on another branch?

    1. git commit
    2. git blame
    3. git tag
    4. git stash

    Explanation: 'git stash' enables temporary saving of changes for later use, perfect for handling urgent tasks. 'git commit' creates a permanent commit, 'git tag' marks versions, and 'git blame' shows line authorship.

  6. Understanding Code Changes with git blame

    Which command helps determine who changed a specific line in a file and when, aiding in debugging regressions?

    1. git push
    2. git fetch
    3. git bisect
    4. git blame

    Explanation: 'git blame' shows the author and timestamp for each line, useful for tracing changes. 'git bisect' finds the commit that introduced bugs, while 'git push' and 'git fetch' handle remotes.

  7. Finding the Bug-Introducing Commit

    If you want to use a binary search to quickly discover which commit introduced a bug, which Git command should you use?

    1. git stash
    2. git log
    3. git bisect
    4. git revert

    Explanation: 'git bisect' helps identify the offending commit efficiently. 'git revert' undoes changes, 'git stash' temporarily saves changes, and 'git log' displays history.

  8. Advanced Inspection with git log

    What is a benefit of using 'git log --oneline --graph --all' for senior developers?

    1. Temporarily saving code changes
    2. Backing up the repository
    3. Creating a pull request
    4. Understanding the project's branching strategy and evolution

    Explanation: 'git log --oneline --graph --all' provides a detailed visual representation of commit history and branches. The other options involve different commands.

  9. Safe Undo on Shared Branches

    Why should a senior developer use 'git revert' instead of 'git reset' on a shared branch?

    1. Because 'git reset' creates tags automatically
    2. Because 'git revert' creates a new commit and does not rewrite history
    3. Because 'git reset' is unavailable on shared branches
    4. Because 'git revert' deletes code without warning

    Explanation: 'git revert' safely undoes a commit by making a new one, ensuring shared branch history is preserved. 'git reset' rewrites history and is unsafe for shared use. The other options are inaccurate.

  10. Managing Releases with git tag

    Which Git command allows you to mark version releases, making it easier to manage rollbacks and CI/CD pipelines?

    1. git commit
    2. git tag
    3. git stash
    4. git branch

    Explanation: 'git tag' marks repository versions useful for releases. 'git stash' saves temporary changes, 'git commit' records modifications, and 'git branch' manages branches, not release versions.