Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Git & GitHub Module 5

GitHub and remotes interview questions

Interview questions on gitHub and remotes: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.

12 questions: 4 warm-ups and 8 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    Why should you check a host key fingerprint before answering "yes" to a first SSH connection to GitHub?

    Answered in the lesson Set up GitHub: account, 2FA and SSH keys

  2. Fresher

    What is the difference between main and origin/main in your clone?

    Answered in the lesson Remotes and cloning: origin and tracking branches

  3. Fresher

    What is the difference between git fetch and git pull?

    Answered in the lesson Sync work with fetch, pull and push

  4. Fresher

    How is a fork different from a clone?

    Answered in the lesson Forks: contribute where you cannot push

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Fresher to mid

    A teammate pasted a fine-grained personal access token with write access to your team's main repository into a busy team chat ten minutes ago. Walk through what you do in the next fifteen minutes, in order, and what you change so that it cannot happen again.

    What it tests
    The order of an incident response for an exposed credential (revoke before cleaning up), checking for misuse, a least-privilege replacement, and removing the habit that caused the leak.
    First step
    Revoke the token before anything else. The message has been readable for ten minutes, so assume someone has copied it; deleting the message first only hides it from you. Then work out what the token was allowed to do and what it was used for since the leak.
    Follow-ups

    From the lesson Set up GitHub: account, 2FA and SSH keys

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  2. Fresher to mid

    On a college network, git push over SSH hangs for about a minute and then fails, while github.com opens normally in the browser. How do you confirm what is wrong, and how do you keep using your SSH key on that network?

    What it tests
    Telling a network block from a key problem, SSH over port 443 at ssh.github.com, host-key checks under a new name, and HTTPS with a credential helper as the fallback.
    First step
    Separate a network problem from a key problem. A key GitHub rejects fails within a second with Permission denied (publickey); a blocked port makes ssh wait for a TCP connection until it gives up. Run ssh -vT git@github.com and see whether the connection is ever established.
    Follow-ups

    From the lesson Set up GitHub: account, 2FA and SSH keys

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Fresher to mid

    git status says "Your branch is up to date with 'origin/main'", yet a teammate says they pushed to main an hour ago. Explain how both can be true, and how you check what is really on the server without changing any of your work.

    What it tests
    Remote-tracking branches as a cache that only fetch, pull and push update, git fetch against git ls-remote, and reading ahead and behind counts.
    First step
    git status compares main with refs/remotes/origin/main, a ref in your own repository that changes only when this repository talks to the remote. If nobody here has fetched since the teammate pushed, that copy is an hour old. git fetch updates only remote-tracking branches; run it, then git status again.
    Follow-ups

    From the lesson Remotes and cloning: origin and tracking branches

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Fresher to mid

    You created a GitHub repository with a README and a licence, added it as origin to a project with forty local commits, and git push -u origin main was rejected. Explain the rejection, and compare two ways to fix it.

    What it tests
    Separate histories with no common commit, why a push must be a fast-forward, pull --rebase against a merge with --allow-unrelated-histories, and when a forced push would be acceptable.
    First step
    GitHub's main already has a commit, the one that added the README and the licence, and your main does not contain it, so moving the remote branch to your commit would drop it. Fetch it and look at both histories: git fetch origin, then git log --oneline --graph --all shows two separate first commits.
    Follow-ups

    From the lesson Remotes and cloning: origin and tracking branches

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  5. Fresher to mid

    Your git push to main is rejected as non-fast-forward, and a colleague suggests git push --force. Explain what the rejection protects, why the suggestion is wrong, and the safe sequence of commands, including what you check before you push again.

    What it tests
    The fast-forward rule, what a forced push throws away, the fetch, integrate, test and push sequence, choosing rebase or merge, and checking the result before pushing.
    First step
    The remote's main has commits that your main does not contain, so moving it to your commit would drop them, and --force does exactly that. Run git fetch, then git log --oneline --graph main origin/main to see both sides before you decide how to integrate.
    Follow-ups

    From the lesson Sync work with fetch, pull and push

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  6. Mid to senior

    Explain what git push --force-with-lease protects against, describe a situation in which it still overwrites a colleague's commit, and say what --force-if-includes adds. Then give the commands you would use to update a rebased feature branch that a colleague also pushes to.

    What it tests
    How a lease compares the remote branch with your remote-tracking branch, how a background fetch renews it, the reflog check of --force-if-includes, and a safe update of a shared branch.
    First step
    A lease means: overwrite the remote branch only if it still points where my origin/<branch> says it does. The weak point is that origin/<branch> can move without you looking at it, for example when an editor runs git fetch every few minutes.
    Follow-ups

    From the lesson Sync work with fetch, pull and push

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  7. Fresher to mid

    A contributor's fork has two commits on main that upstream does not have, every sync now makes a merge commit, and their open pull request shows those commits too. How did this happen, and how do you repair the fork without losing the two commits?

    What it tests
    Why commits on a fork's main break fast-forward syncs, moving the commits to a topic branch, resetting main to upstream/main, a safe forced push to the fork, and clean pull requests.
    First step
    The two commits went straight onto the fork's main, so main and upstream/main have diverged: every plain merge from upstream adds a merge commit, and a pull request opened from main carries everything on it. First put the two commits somewhere safe with git branch keep-work main.
    Follow-ups

    From the lesson Forks: contribute where you cannot push

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  8. Mid to senior

    Set up a contributor's clone so that a plain git pull on main reads from the original project and a plain git push writes to their fork. Name the settings, show how you would verify them, and describe one way this setup can surprise someone.

    What it tests
    remote.pushDefault and branch upstreams, push.default=simple in a triangular workflow, checking with --dry-run, and surprises such as new branches and @{push}.
    First step
    Two remotes and two settings. origin is the fork and upstream the original. git branch --set-upstream-to upstream/main makes pull read from the original, and git config remote.pushDefault origin sends every push without a push remote of its own to the fork.
    Follow-ups

    From the lesson Forks: contribute where you cannot push

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All Git & GitHub interview questions · The Git & GitHub track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.