WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Git · Intermediate · question 36 of 100

How do you manage multiple remote repositories in a single local Git repository?

📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

In Git, it’s possible to manage multiple remote repositories in a single local repository. This can be useful when working on a project that has multiple remote repositories, such as a main repository and a forked repository.

Here’s how to manage multiple remote repositories in Git:

Add the remote repositories to your local repository using the git remote add command. You can use any name you like for the remote repository (e.g., origin, upstream, forked, etc.).

    git remote add origin git://github.com/user/repo.git
    git remote add upstream git://github.com/otheruser/repo.git
    git remote add forked git://github.com/myuser/repo.git

Verify that the remote repositories were added successfully using the git remote -v command.

    git remote -v
    origin  git://github.com/user/repo.git (fetch)
    origin  git://github.com/user/repo.git (push)
    upstream  git://github.com/otheruser/repo.git (fetch)
    upstream  git://github.com/otheruser/repo.git (push)
    forked  git://github.com/myuser/repo.git (fetch)
    forked  git://github.com/myuser/repo.git (push)

Push changes to the appropriate remote repository using the git push command and the name of the remote repository.

    # Push changes to the origin remote repository
    git push origin master
    
    # Push changes to the forked remote repository
    git push forked mybranch

Pull changes from the appropriate remote repository using the git pull command and the name of the remote repository.

    # Pull changes from the upstream remote repository
    git pull upstream master
    
    # Pull changes from the forked remote repository
    git pull forked mybranch

By default, Git will use the origin remote repository for push and pull operations. To push or pull changes to a different remote repository, you can specify the name of the remote repository as an argument to the git push or git pull command.

In summary, to manage multiple remote repositories in a single local Git repository, you can add the remote repositories using the git remote add command, verify that they were added successfully using the git remote -v command, and push or pull changes to the appropriate remote repository using the git push or git pull command with the name of the remote repository.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Git interview — then scores it.
📞 Practice Git — free 15 min
📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

All 100 Git questions · All topics