1. What is `git reflog` and when is it indispensable?
Reflog records movements of HEAD and refs (even orphaned). It’s crucial for recovering "lost" commits after resets/rebases or branch deletions.
Get the Preplance app for a seamless learning experience. Practice offline, get daily streaks, and stay ahead with real-time interview updates.
Get it on
Google Play
4.9/5 Rating on Store
Accenture · Git & Version Control
Practice Git & Version Control questions specifically asked in Accenture interviews – ideal for online test preparation, technical rounds and final HR discussions.
Questions
51
Tagged for this company + subject
Company
Accenture
View company-wise questions
Subject
Git & Version Control
Explore topic-wise practice
Go through each question and its explanation. Use this page for targeted revision just before your Accenture Git & Version Control round.
Reflog records movements of HEAD and refs (even orphaned). It’s crucial for recovering "lost" commits after resets/rebases or branch deletions.
For complete preparation, combine this company + subject page with full company-wise practice and subject-wise practice. You can also explore other companies and topics from the links below.
Use `git log --grep "keyword"` to locate by message; then `git show <hash>` (optionally `-p --stat`) to view the diff and metadata.
Create a branch (`git switch -c`) if you intend to keep commits.
Squash condenses all PR commits into one for a tidy history.
Rewrite only private/unpushed history to avoid disrupting collaborators.
CODEOWNERS maps file globs to teams/users, auto-requesting reviews and enforcing approvals.
It refuses to overwrite remote work you haven’t fetched, offering a safety check.
A repository stores your project files and their version history. A local repo lives on your machine (.git); a remote repo (e.g., GitHub/GitLab) is a shared copy used for collaboration and backup.
Stage with `add`, create a snapshot with `commit`, then publish with `push`.
A commit is a snapshot of staged changes with metadata (hash, author, time). Clear messages explain intent, aid code review, and improve traceability.
A conflict arises when Git can’t auto-merge edits (e.g., same line differs). Open files, choose the correct content, save, `git add` the fixes, then `git commit` (or `--continue`).
`git switch -c <name>` is the newer, intent-specific command. The classic equivalent is `git checkout -b <name>`.
`merge` combines histories and may create a merge commit; it preserves chronology from all contributors. `rebase` rewrites commits on top of a new base for a linear history—clean but dangerous if used on shared/pushed commits. Rebase private branches; avoid rebasing public history.
First push with `--set-upstream` ties the local branch to its remote tracking branch.
`--oneline --graph --decorate` for a compact, visual branch graph; `--stat` to see per-file change summary; `-p` to display patch/diffs for each commit.
Stage the missing change, then amend to rewrite the tip commit (avoid on public history).
`--fixup <hash>` creates a targeted fix commit labeled for autosquash. Later `rebase -i --autosquash` reorders and squashes fixups onto their intended commits automatically, keeping a tidy history.
`git remote set-url` updates the fetch/push URLs for a named remote.
`--tags` tells Git to send all tag refs to the target remote.
A submodule embeds another repo at a specific commit. After cloning, run `git submodule init` then `git submodule update` (or `git submodule update --init --recursive`) to fetch and checkout submodule contents.
`git restore <path>` restores file content in working tree from HEAD (or a commit). `git restore --staged <path>` un-stages changes (like `git reset <path>`). They split file restore from branch switching for clarity.
Rebase copies your commits onto the target tip (new IDs), producing a straight line; merge records a join, keeping parallel history.
Rebasing rewrites commit IDs, breaking collaborators’ histories. It’s safe on private/local branches before pushing or when everyone coordinates (e.g., force-push with lease) and consumers are ready.
Use `git reflog` to find the pre-rebase HEAD (e.g., `HEAD@{1}`) and `git reset --hard <that-id>` or create a rescue branch from it. Reflog records past HEAD positions.
`--mixed` (default) moves HEAD and resets index to the commit, keeping your working files.
`--no-ff` keeps a merge node even if fast-forward is possible, preserving feature context.
1) `git merge origin/main` → non-destructive, may create merge commits. 2) `git rebase origin/main` → linear history, rewrites commits (avoid if already shared).
This ties the current local branch to a remote tracking branch for pull/push defaults.
Review promptly, be specific and kind, ask clarifying questions, suggest concrete changes, verify tests/docs, pull locally when needed, and approve only after required checks pass.
Trunk-based or short-lived feature branches; protect `main` with CI; feature toggles for incomplete work; cut `release/*` branch weekly for stabilization; hotfix branches from `main`; merge via PR with squash; tag releases.
`git stash` (or `git stash push`) stores current tracked changes and resets the worktree.
`--all` (aka `-a`) includes ignored and untracked files along with tracked changes.
`-p/--patch` lets you interactively pick hunks to stash.
`-x` makes `clean` also remove ignored files; pair with `-f` to apply.
Draft PRs invite early review without merge intent.
Set at repo scope with `git config pull.rebase true` (or `--global` for all repos).
When you need only specific commits (e.g., a hotfix) without bringing other work, to keep a minimal, controlled change set.
`--signoff` appends a DCO sign-off line to the commit message.
`-a` creates an annotated tag and `-m` sets its message.
MAJOR → incompatible, MINOR → new compatible features, PATCH → bug fixes.
Use SemVer for GA (e.g., vX.Y.Z), suffix `-rc.N`/`-beta.N` for candidates, `-hotfix.N` for urgent patches, and build metadata for CI artifacts. Protect tags, sign GA tags, auto-generate notes via CI.
Branch protection with mandatory reviews and passing CI prevents broken code and history rewrites.
Acknowledge the concern, provide evidence (benchmarks, standards), seek compromise, or escalate to documented guidelines/architects. Never ignore feedback; document the decision in the PR for future readers.
Early collaboration reduces rework and aligns on approach.
Gentle automation plus education shapes behavior without stalling delivery.
`-u` stages tracked file modifications and deletions; it skips new untracked files.
Pushing an empty ref (`:<name>`) deletes the remote branch. Modern alternative: `git push origin --delete feature/login`.
Squash merge maintains a clean history with one commit representing the PR.
`git switch -C` creates (or resets) and checks out the branch in one step.
GitHub Flow favors small feature branches off main with PR review and continuous delivery.
Automate SemVer bumps on protected branch and create annotated (optionally signed) tags with release notes.