1. How do you create a local branch that tracks an existing remote branch?
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.
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
Git & Version Control · Question Set
Branching & Merging Strategies — Merge, Rebase, Fast-Forward interview questions for placements and exams.
Questions
14
Included in this set
Subject
Git & Version Control
Explore more sets
Difficulty
Mixed
Level of this set
Go through each question and its explanation. Use this set as a focused practice pack for Git & Version Control.
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.
For complete preparation, combine this set with full subject-wise practice for Git & Version Control. You can also explore other subjects and sets from the links below.
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.
Squash yields a single commit; good for tidy history, but loses granular commit info.
Branches isolate work so features, fixes, and experiments can proceed without impacting the main line. They allow concurrent workflows, easier code review via PRs, and controlled integration back to trunk.
If no divergence exists, Git advances the pointer (no merge commit).
`--no-ff` keeps a merge node even if fast-forward is possible, preserving feature context.
Merge preserves history with a merge commit—good for shared branches. Rebase rewrites the feature to sit atop main—clean linear history, ideal before opening a PR. Avoid rebasing public branches.
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.
Policy: feature branches rebase onto latest main; PRs merge with squash or rebase-merge; disallow merge commits on main. Steps: `git fetch`, `git rebase origin/main`, resolve, push with `--force-with-lease`, then squash-merge PR.
Octopus merges combine multiple heads, usually for automated, conflict-free integrations.
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 switch -C` creates (or resets) and checks out the branch in one step.