DEV Community

Cover image for Working with multiple git remotes
Bert Heyman
Bert Heyman

Posted on

Working with multiple git remotes

What is a remote

Platforms like Github are really useful!
They're like a cloud service, but with enhanced features specifically for code. A well written history has saved me quite a bit of time in the past.

The remote of a repo is the location where it is stored.
Typically a url like github.com/org/your-project.
Less known is that you can have multiple remotes.

Adding a new remote

  1. Create a new (empty!) repo
  2. Connect your local repo to the new remote.
    You'll need to name the remote (the default one is called origin), for example "personal" or "gitlab" (another provider).
    Command: git remote add name-for-remote repo-url
    Example: git remote add personal github.com/org/your-project

  3. Push to the remote of your choosing

    • Set a default: git config push.default remote-name
    • Or specify the remote to push to: git push remote-name branch-name

Top comments (0)