Remote Workflows Questions with Answers

19 practice questions on Remote Workflows (Git & DevOps) with answers and step-by-step solutions. Try 10 samples below, then practise all 19 free in the AptiNest app.

Sample questions

Question 1Easy

Which command lists the configured remotes with their URLs?

  1. git log --remote
  2. git config --remotes
  3. git remote -v
  4. git branch -r

Answer: C. git remote -v

Explanation

git remote -v shows each remote's fetch and push URLs. git branch -r lists remote-tracking branches.

Step-by-step solution

  1. git remote lists remote names.
  2. -v (verbose) adds the fetch and push URLs.

Why the other options are wrong

  • A. git log has no --remote option for listing remotes.
  • B. git config has no --remotes option.
  • D. git branch -r lists remote-tracking branches, not URLs.

Tip: Where does this repo push? git remote -v.

Question 2Easy

In a fork workflow, which remote name is conventionally used for the original repository?

  1. upstream
  2. origin
  3. fork
  4. main

Answer: A. upstream

Explanation

origin points to your fork, upstream to the original project you sync from.

Step-by-step solution

  1. Fork on the platform.
  2. Clone your fork (origin).
  3. Add the original as upstream.

Why the other options are wrong

  • B. origin is your fork.
  • C. Not a convention.
  • D. main is a branch name.

Question 3Easy

Which command adds a remote named origin pointing to a URL?

  1. git clone add origin <url>
  2. git push origin --add <url>
  3. git config origin <url>
  4. git remote add origin <url>

Answer: D. git remote add origin <url>

Explanation

git remote add <name> <url> registers a new remote in the repository config.

Step-by-step solution

  1. Choose a name, usually origin.
  2. Run git remote add.
  3. Verify with git remote -v.

Why the other options are wrong

  • A. clone has no add.
  • B. Push does not register remotes.
  • C. Wrong config key.

Question 4Easy

Which command shows your remotes and their URLs?

  1. git remote -v
  2. git remotes
  3. git url
  4. git origin

Answer: A. git remote -v

Explanation

git remote -v lists each remote with its fetch and push URL.

Step-by-step solution

  1. Run git remote -v.
  2. Each line shows name and URL.
  3. Fetch and push URLs are listed.

Why the other options are wrong

  • B. No such command.
  • C. No such command.
  • D. No such command.

Question 5Medium

How do you delete the remote branch feature on origin?

  1. git branch -d origin/feature
  2. git remote remove feature
  3. git fetch --delete feature
  4. git push origin --delete feature

Answer: D. git push origin --delete feature

Explanation

git push origin --delete feature (or git push origin :feature) removes the branch on the server.

Step-by-step solution

  1. Deleting a remote branch is a push action.
  2. Use --delete.
  3. Prune stale local refs with git fetch --prune.

Why the other options are wrong

  • A. That fails; it targets local branches.
  • B. remote remove removes the whole remote.
  • C. Fetch only downloads.

Question 6Medium

What does git fetch --prune additionally do?

  1. Deletes local branches that were merged, along with their commits
  2. Deletes remote branches
  3. Removes local remote-tracking branches that no longer exist on the remote
  4. Compresses the repository

Answer: C. Removes local remote-tracking branches that no longer exist on the remote

Explanation

Prune cleans stale origin/xyz references after branches were deleted remotely.

Step-by-step solution

  1. Fetch updates refs.
  2. Prune checks which remote branches vanished.
  3. Stale origin/* refs are removed.

Why the other options are wrong

  • A. Local branches are not touched.
  • B. Remote is never changed by fetch.
  • D. That is git gc.

Question 7Medium

git push is rejected with "Updates were rejected because the remote contains work that you do not have locally". What should you do?

  1. Run git commit --amend and then push without changes
  2. Delete the remote branch and push your branch again
  3. Fetch and integrate the remote changes, then push again
  4. Keep running git push until the remote accepts it

Answer: C. Fetch and integrate the remote changes, then push again

Explanation

The remote branch has commits yours lacks, so your push is not a fast-forward. Integrate them first instead of overwriting someone else's work.

Step-by-step solution

  1. The remote has commits you do not have.
  2. Pushing would not be a fast-forward, so it is rejected.
  3. Fetch and integrate (merge or rebase), then push.

Why the other options are wrong

  • A. Amending does not add the missing remote commits.
  • B. Deleting the remote branch destroys others' work.
  • D. Retrying gives the same rejection.

Tip: Push rejected? Pull (fetch + integrate), then push.

Question 8Medium

What does the -u flag do in git push -u origin feature?

  1. Sets origin/feature as the upstream for later push and pull
  2. Pushes every local branch to origin, not just the current one
  3. Undoes the previous push and replaces it with the current one
  4. Pushes only the unstaged changes in the working directory

Answer: A. Sets origin/feature as the upstream for later push and pull

Explanation

-u (--set-upstream) records the tracking relationship.

Step-by-step solution

  1. git push origin feature pushes the branch.
  2. -u (--set-upstream) also records origin/feature as its upstream.
  3. Later, plain git push and git pull know where to go.

Why the other options are wrong

  • B. Pushing all branches is --all.
  • C. There is no undo-push flag.
  • D. Only commits are pushed, never unstaged changes.

Tip: First push of a new branch: git push -u origin name.

Question 9Hard

Why is git push --force-with-lease safer than git push --force?

  1. It automatically creates a backup branch on the remote first
  2. It refuses if the remote branch moved since your last fetch
  3. It only works on the main branch, which prevents accidents
  4. It uploads faster because it skips the pack negotiation step

Answer: B. It refuses if the remote branch moved since your last fetch

Explanation

--force-with-lease checks that the remote branch is still where your remote-tracking ref says it is, so you do not silently delete commits someone else pushed.

Step-by-step solution

  1. --force overwrites the remote branch no matter what.
  2. --force-with-lease first checks the remote is still where you last fetched it.
  3. If someone pushed since, it refuses, so their work is not lost.

Why the other options are wrong

  • A. No backup branch is created.
  • C. It works on any branch.
  • D. It has no speed advantage.

Tip: If you must force-push, use --force-with-lease.

Question 10Hard

Why does git push --force-with-lease protect teammates better than --force?

  1. It pushes your commits to a temporary branch on the server instead
  2. It fails if the remote branch moved since you last fetched
  3. It signs the commit
  4. It only force-pushes tags

Answer: B. It fails if the remote branch moved since you last fetched

Explanation

The lease check ensures you do not overwrite commits you have not seen.

Step-by-step solution

  1. You fetched the remote tip.
  2. If someone pushed after, the tip differs.
  3. The push is rejected.

Why the other options are wrong

  • A. No temporary branch is made.
  • C. Signing is unrelated.
  • D. It affects branches too.

Practise all 19 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Git & DevOps topics · All topics