Multiple Git Remotes

Many people where I work have a tendency to have multiple copies of our git repositories. They do this because when using a gitflow structure, and a slow moving team workflow, you tend to have a task that you send off to testing, and then you wait on that branch for far longer than should be normal until you eventually get to pull request in your change.

When you have lots of developers, this means merging develop in. A lot.

Unfortunately, I tend to not like this approach. I just stash my changes, run some quick git commands, and then pop my changes, and am back to work without having multiple repositories to deal with.

Imagine my frustration when I started working on a fork of our main product, and suddenly had to have a copy of the repo for our fork, and a copy of the repo for the original. Not a common problem I know, but it was still quite painful for me.

In git, you can have multiple remotes. this means that you can push and pull branches from more than one remote server. Also, you can merge branches between the two repos as well. Suppose you have a feature for the current generation of your application, and it needs to be implemented in your next generation app as well. No git patches or copy pasting files. just have a branch that tracks your current generation, and a branch that tracks your remote generation and merge them! Its basically magic only much simpler to do

there will by default be an origin, which you just have to decide which version of the app is origin. I chose for next generation to be origin, and current generation to be my added remote.

When checking out a branch, you just put the remote first

when you track the remote branch, doing a git push will automatically push it back to the correct remote.

When you create a new local branch, and push it, you just need to make sure you have the right parameters for tracking

You can also set the remote upstream when you create the branch instead of waiting until you push the branch


Leave a Reply

Your email address will not be published. Required fields are marked *