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
git clone git://server.local/repot.git sets up
origin like this:
- Why do some repository URLs end in .git while others don't?
- Clone SSH repository with non-standard port number to SourceTree
- How can I break the link of git config <url>.insteadOf <url>
- Django git conflict affecting url.py
- How to check the validity of a remote git repository URL?
- Why are Github project document page urls case sensitive? What are the negative effects?
$ 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.
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).
git config --global url."ssh://server.local/realrepopath/".pushInsteadOf git://server.local/
should do the trick.