1. You want to work on two branches simultaneously from the same repo without stashing. What feature helps?
`git worktree add ../path <branch>` creates another working tree tied to the same `.git` data, enabling parallel checkouts.
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
Tech Mahindra · Git & Version Control
Practice Git & Version Control questions specifically asked in Tech Mahindra interviews – ideal for online test preparation, technical rounds and final HR discussions.
Questions
35
Tagged for this company + subject
Company
Tech Mahindra
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 Tech Mahindra Git & Version Control round.
`git worktree add ../path <branch>` creates another working tree tied to the same `.git` data, enabling parallel checkouts.
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 switch -c feature origin/feature` or `git checkout --track origin/feature`. This sets upstream so pulls/pushes use the remote branch by default.
Rewriting history creates new commits; force-push would be required and can disrupt collaborators.
Run `git rebase main`; when conflict occurs: fix files, `git add <files>`, `git rebase --continue`. Use `git rebase --skip` to drop a commit if appropriate, or `git rebase --abort` to revert.
Conventional Commits use type(scope?): subject — e.g., feat, fix, chore, docs — aiding automation and changelogs.
Enable with `git config rerere.enabled true` to speed repeated merges/rebases with identical conflicts.
`origin` is the default remote alias created by `git clone`.
Use it to fix the last commit’s message or add missed changes. It rewrites history, so avoid amending commits already pushed/shared.
A fast-forward moves the branch pointer when no divergent commits exist; no merge commit is created. `--no-ff` forces a merge commit to preserve feature-branch context—useful for code review traceability and keeping logical units in history.
`git cherry-pick <hash>` applies the changes from a specific commit onto the current branch. Commonly used to backport a hotfix commit from `main` to a release branch without merging all other changes.
Annotated tags store tagger, date, and message—ideal for releases. Create with `git tag -a v1.2 -m "Release"` and push using `git push origin v1.2`.
Keep subject line ≤50 chars in imperative mood (e.g., "Fix crash on null input"). Add a blank line, then a body explaining what and why (context, impact, links).
`--soft` moves HEAD only (keeps Index/WT), `--mixed` moves HEAD and resets Index (keeps WT), `--hard` resets HEAD, Index, and Working Tree (destructive).
An upstream branch is the remote branch your local branch integrates with by default for pull/push. Set it via `git branch --set-upstream-to=origin/main` or on first push using `git push -u origin <branch>`.
`push.default=simple` pushes the current branch to its upstream of the same name and rejects if names differ. `git push --all` pushes all local branches that have matching names to the remote.
`--tags` tells Git to send all tag refs to the target remote.
Run `git rebase -i HEAD~3`; change second/third `pick` to `squash` (or `fixup`); save, then edit the combined message and complete the rebase.
Use it to transplant a range of commits onto a different base, skipping earlier ones. Example: move `featureA` commits that diverged from `topic` onto `main`: `git rebase --onto main topic featureA`.
`revert` adds a new commit that negates a past one; safe for shared branches.
Revert creates a new inverse commit, preserving subsequent history.
Use `git revert --no-commit A^..B` to stage inverse changes for the range, review, then `git commit` once. Or `git revert A^..B` to create multiple revert commits.
Octopus merges combine multiple heads, usually for automated, conflict-free integrations.
It stashes only unstaged changes while leaving the index intact. Useful before running tests/CI on exactly what is staged for commit without noise from local WIP.
`git clean` removes untracked files/dirs from the working tree. It permanently deletes files not tracked by Git, so use `-n` (dry-run) first to preview.
Git Flow uses persistent main and develop branches; feature/release/hotfix are short-lived.
Rebase+merge rewrites branch commits on top of base to keep history linear.
`squash` merges commits and lets you edit a combined message; `fixup` discards the later message.
Tag fixups (`fixup! subject`) then run interactive rebase with `--autosquash`.
Pushing a specific tag uses `git push <remote> <tag>`; `--tags` pushes all tags.
Valid format: MAJOR.MINOR.PATCH-PRERELEASE+BUILD; leading 'v' is not part of SemVer core.
`A..B` shows commits reachable from B and not A; `...` is symmetric difference.
`git init` bootstraps a repository in the current folder; `git clone` fetches an existing repo, files, branches, and history.
`pop = apply + drop`. Use `apply` to reuse later, `pop` to consume once.
Smaller diffs are easier to review thoroughly and roll back when needed.
Threat-aware review plus automated secret scanning and SCA improves security posture.