How to set up a repo so that when cloned it has two different adresses for pushing and fetching?

I have a git repository living at git://server.local/repo.git

Cloning with git clone git://server.local/repot.git sets up origin like this:

$ git remote -v
origin  git://server.local/repo.git (fetch)
origin  git://server.local/repo.git (push)

But I would like this instead:

$ git remote -v
origin  git://server.local/repo.git (fetch)
origin  ssh://server.local/realrepopath/repo.git (push)

I want this to be done automatically when cloning (without changing manually the remote URL).

Is that possible ?

I don’t want to have to run any command or script after the cloning is done. I would like to configure the remotes URL on the server so that I don’t have to manually change them after cloning a repository.

  • Local Git repository url in Visual Studio error: Unsupported URL protocol
  • Which URL should I use when adding a Git submodule?
  • BitBucket - How to retrieve all repository urls from a server
  • Clone SSH repository with non-standard port number to SourceTree
  • GitHub API returned Url meaning
  • git clone: what's the difference between url… and url git://
  • Why am I getting the error on svn client “XML parse error at line 1 no element found” when accessing VisualSVN Server?
  • GitHub source dynamic navigation
  • 3 Solutions collect form web for “How to set up a repo so that when cloned it has two different adresses for pushing and fetching?”

    Looks like the gerrit solution is still the accepted one. Check out this answer to see how it can be done with a simple script.

    Once the repository is cloned you can execute

    git remote set-url origin git://server.local/repo.git
    git remote set-url --push origin ssh://server.local/realrepopath/repo.git

    Unfortunately, there doesn’t seem to be a way to run scripts or hooks on a new git clone (as far as I know).

    The command

    git config --global url."ssh://server.local/realrepopath/".pushInsteadOf git://server.local/

    should do the trick.

    Git Baby is a git and github fan, let's start git clone.