Discover key Git commands that elevate developers from basic usage to senior expertise, covering history management, bug fixing, release tasks, and safe collaboration.
What is the main reason senior developers use 'git rebase' before raising a pull request?
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'.
Which Git command lets you apply a specific commit from one branch to another for selective bug fixes?
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.
Which Git command helps you recover lost commits even after running dangerous operations like 'git reset --hard'?
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.
What is the key difference between 'git reset --soft' and 'git reset --hard'?
Explanation: '--soft' keeps your changes staged after resetting, while '--hard' permanently deletes them. The other options incorrectly describe actions unrelated to reset.
During mid-work, what Git command allows you to quickly save uncommitted changes to handle an urgent production bug on another branch?
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.
Which command helps determine who changed a specific line in a file and when, aiding in debugging regressions?
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.
If you want to use a binary search to quickly discover which commit introduced a bug, which Git command should you use?
Explanation: 'git bisect' helps identify the offending commit efficiently. 'git revert' undoes changes, 'git stash' temporarily saves changes, and 'git log' displays history.
What is a benefit of using 'git log --oneline --graph --all' for senior developers?
Explanation: 'git log --oneline --graph --all' provides a detailed visual representation of commit history and branches. The other options involve different commands.
Why should a senior developer use 'git revert' instead of 'git reset' on a shared branch?
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.
Which Git command allows you to mark version releases, making it easier to manage rollbacks and CI/CD pipelines?
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.