Skip to content

Instantly share code, notes, and snippets.

@taldanzig
Created January 23, 2013 06:38
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save taldanzig/4602638 to your computer and use it in GitHub Desktop.
Save taldanzig/4602638 to your computer and use it in GitHub Desktop.
Make push/pull work with a remote non-bare repository

Make push/pull work with a remote non-bare repository

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.

@gthaker
Copy link

gthaker commented Dec 7, 2023

This is 11 years old and not a single comment from any user. Does this still work with modern 'git' versions? Is this still best way to handle this? The usecase is real.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment