Git Git Remote Operations 1 β Questions and Answers
Question 1: Which command adds a new remote repository with the alias `origin`?
- git remote origin add <url>
- git remote add origin <url> (Correct answer)
- git add remote origin <url>
- git set remote origin <url>
Correct answer: git remote add origin <url>
The `git remote add origin <url>` command registers a new remote repository under the alias `origin`.
Question 2: What does `git fetch` do compared to `git pull`?
- They are identical
- fetch downloads changes but does not merge them; pull downloads and merges (Correct answer)
- fetch only updates tags; pull updates branches
- fetch merges automatically; pull asks for confirmation
Correct answer: fetch downloads changes but does not merge them; pull downloads and merges
The `git fetch` command downloads remote changes into remote-tracking branches without modifying your working branch, while `git pull` fetches and then merges.
Question 3: How do you push a local branch `feature` to the remote `origin` and set it as the upstream?
- git push origin feature
- git push -u origin feature (Correct answer)
- git push --set-upstream feature origin
- git push origin --track feature
Correct answer: git push -u origin feature
The `-u` (or `--set-upstream`) flag sets the remote branch as the upstream for the local branch, enabling future `git push` without arguments.
Question 4: Which command removes a remote called `upstream` from your configuration?
- git remote delete upstream
- git remote remove upstream (Correct answer)
- git remove remote upstream
- git remote -d upstream
Correct answer: git remote remove upstream
The `git remote remove upstream` command removes the remote named `upstream` and all associated remote-tracking branches.
Question 5: What is a remote-tracking branch?
- A branch on the remote server
- A local read-only reference that mirrors the state of a remote branch as of the last fetch (Correct answer)
- A branch that automatically pushes on every commit
- A backup of the local main branch
Correct answer: A local read-only reference that mirrors the state of a remote branch as of the last fetch
Remote-tracking branches (e.g., `origin/main`) are local references that represent the last known state of branches on the remote.
Question 6: How do you delete a remote branch called `old-feature` on `origin`?
- git branch -d origin/old-feature
- git push origin --delete old-feature (Correct answer)
- git remote remove origin/old-feature
- git delete origin old-feature
Correct answer: git push origin --delete old-feature
The `git push origin --delete old-feature` command removes the `old-feature` branch from the remote repository.
Which command adds a new remote repository with the alias `origin`?