1. How do you set the current local branch to track `origin/develop`?
Use `git branch --set-upstream-to=<remote>/<branch>` from the local branch. Alternatively, the first push can set it: `git push --set-upstream origin <branch>`.
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
Git Branching & Collaboration — Core 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 branch --set-upstream-to=<remote>/<branch>` from the local branch. Alternatively, the first push can set it: `git push --set-upstream origin <branch>`.
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.
Use `-d` for safe deletion (already merged). `git fetch --prune` cleans stale remote-tracking refs.
Branches let you isolate work (features, fixes, experiments) without disrupting the main line. In Git, branches are lightweight pointers to commits, so creating/switching is fast and storage-efficient.
`git switch -c <name>` is the newer, intent-specific command. The classic equivalent is `git checkout -b <name>`.
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 merge <branch>` integrates that branch into the current HEAD.
`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.
`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.
`revert` creates a new commit that negates the changes without rewriting history, safe for shared branches.
`pull --rebase` rewrites local work on top of fetched commits, avoiding a merge commit for a linear history.
`--oneline --graph --decorate` for a compact, visual branch graph; `--stat` to see per-file change summary; `-p` to display patch/diffs for each commit.
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`.
Edit to resolve, stage resolved files, then commit. During rebase, you’d use `git rebase --continue` after `git add`.