3

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 ?

Edit: 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.

  • Assuming there is a manual solution, then an automated solution is trivially achieved via a script... – Oliver Charlesworth Feb 09 '14 at 20:16
  • Could you setup two separate remotes and push to one and pull from the other? – T0xicCode Feb 09 '14 at 20:17
  • @OliCharlesworth: I don't want myself or any of my users to have to run any script or command after cloning. Remotes should ideally be set with git for pull/fetch and ssh for push as soon as cloning is done. If it is possible it can only be a server side setting. – John Christopher Feb 09 '14 at 20:53
  • @T0xicCode: I could technically do that but that would require more maintenance and attention to details. – John Christopher Feb 09 '14 at 20:59

3 Answers3

0

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.

Community
  • 1
  • 1
Paul Hicks
  • 13,289
  • 5
  • 51
  • 78
0

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).

ibab
  • 924
  • 7
  • 15
0

The command

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

should do the trick.

Alexey Ten
  • 13,794
  • 6
  • 44
  • 54
  • I tried server side, on the git repository but the setting doesn't apply when cloning on the client side. – John Christopher Feb 10 '14 at 12:23
  • @JohnChristopher, it should not work on server. But you need to run this command only once and this setting will be stored in your config `~/.gitconfig` and work for any repository from server.local. If you change `--global` to `--system` (if you have enough privileges) and this will work for anyone on the client computer. – Alexey Ten Feb 10 '14 at 12:58