Q26 of 40 · Git
How do you manage multiple remotes in Git, and when would a QA engineer need more than one remote?
Short answer
Short answer: `git remote add <name> <url>` registers a remote. Multiple remotes are used when working with forks (origin = your fork, upstream = canonical repo), or syncing between GitHub and an internal mirror. `git fetch --all` fetches all remotes at once.
Detail
A remote is a named alias for a URL. By default, cloning creates one remote called origin. You can have as many remotes as you want.
Fork workflow: the standard open-source (and many enterprise) pattern is to fork the canonical repository, clone your fork (now origin), and add the canonical repo as upstream. You pull new work from upstream and push your own branches to origin. This is common on QA teams that contribute to a shared test framework repo.
Mirror/sync scenario: some enterprises have an internal GitHub Enterprise mirror of an external GitHub repo. A QA engineer might need origin pointing at the internal mirror (for CI access) and external pointing at the public repo (to fetch the latest upstream test fixtures).
Remote-tracking branches: fetching a remote creates local refs like origin/main and upstream/main. These are read-only snapshots — you never commit directly to them. Use them as merge/rebase targets to incorporate remote changes.
Renaming and removing: git remote rename origin github and git remote remove old-mirror keep your remote list tidy. git remote -v shows all remotes with their fetch/push URLs (they can differ, useful for read-only mirrors).
// EXAMPLE
# View all remotes and their URLs
git remote -v
# Add the canonical upstream (after cloning a fork)
git remote add upstream https://github.com/company/test-framework.git
# Fetch all remotes (updates all remote-tracking branches)
git fetch --all
# Sync your fork's main with upstream
git switch main
git rebase upstream/main
git push origin main
# Add an internal mirror as a second remote
git remote add internal https://github.internal.com/company/test-framework.git
# Push to multiple remotes (e.g., origin and internal mirror)
git push origin feature/payment-tests
git push internal feature/payment-tests
# Remove a stale remote
git remote remove old-mirror
# Rename origin to github for clarity
git remote rename origin github