Sometimes it is necessary (and desireable) to work on a git repository on multiple development machines. We want to be able to push and pull between repositories without having to use an intermediary bare repository, and for this to work symetrically in both repositories.
First clone we clone an existing repository:
git clone ssh://user@hostname:/path/to/repo
By default this will name the remote as origin, but let's assume we want to reserve that name for a master repository that commits will eventually get pushed to:
git remote rename origin otherdev
git remote add origin masterhostname:/path/to/master/repo.git
Finally we need to edit our .git/config
. We'll have a section that looks like this:
[remote "otherdev"]
url = ssh://user@hostname:/path/to/repo
fetch = +refs/heads/*:refs/remotes/otherdev/*
Add the following line:
push = +refs/heads/*:refs/remotes/otherdev/*
Now in the original repository add a section as follows:
[remote "otherdev"]
url = ssh://user@otherhost:/path/to/clonedrepo
fetch = +refs/heads/*:refs/remotes/otherdev/*
push = +refs/heads/*:refs/remotes/otherdev/*
Now either repository should be able to push and pull from the other.