0

I have my own private git server at home. At work, i have another team server I set up.

Some of my code is shared, meaning is both on my private server for my private projects, and on the work server for , of course, work projects.

Imagine I clone one of those projects from work, do some work on it, and commit. I do a 'remote add home rhiakath@home:project' , do a 'git push home master', and 'git push origin master'.

But, if i later clone this project again, only the origin remote is present. How can i instruct git to keep my remotes between pushes and clones, so i can always have a work and home remote ( and origin would always be equal to one of those, depending from where i clone ) ?

Thanks

EDIT: Ok, let me clear this a little better. My colleagues would always do a regular clone, and a regular git push origin master, or something. Not 2 origins, or someone else using my home repo, or user. Just want to keep some remotes defined after a push/clone cycle, that's all.

I just want that, after i clone a repo, those two remotes are still defined, so i can do a push home master, and a push work master. Right now, when i clone from the work repo, i have to add again the "home" remote, and push to it, and vice-versa from the home repo.

Joao Pincho
  • 939
  • 2
  • 11
  • 26
  • 1
    That doesn't make sense. You can't assume that everybody who clones a project will have access to all *your* remotes, and they *certainly* wouldn't be able to commit with your username. – user229044 Jun 19 '13 at 14:40
  • I am positive that if you clone the repository with origin and remote, the new repository will have an origin pointing to the local copy. That is, even origin is not copied across. – vhallac Jun 19 '13 at 14:57

1 Answers1

0

Hmm not sure exactly how git or even if git will let you do what you want.. i.e clone a repo with 2 origins, since I think the origin gets auto-set locally to where you cloned it from...

But I would just write some small shell script or program (and commit it your repo) to append the following to your repo's .git/config file:

[remote "alternateorigin"]
url = ssh://hostname/user/reponame.git
fetch = +refs/heads/*:refs/remotes/alternateorigin/*

Replacing the relevant bits of course... the url/protocol might differ depending on how you connect to your remote host. But that's how I'd do it...

unknownprotocol
  • 420
  • 3
  • 10
  • @OP this question might be relevant to your inquiry: http://stackoverflow.com/questions/7731602/how-can-i-clone-a-git-repository-and-keep-remotes – unknownprotocol Jun 19 '13 at 17:09
  • @meagar. people are not supposed to push to my private server. Imagine this: I create two remotes on my local project, one named home, and another named work. I push to both of them. When someone clones ( from work, of course ), he should have three remotes. one home, one work, and one origin. Origin, in this case would be the same as work. @ cesarDV. I know that origin is automatically generated, that's why i can't use it for this. I just want git to save the other remotes i specified, in the project, when i push. that's it. Everybody else keeps using origin. – Joao Pincho Jun 20 '13 at 15:14
  • From that link, this snippet : "Incidentally, even if you use one of those techniques to change the mapping of the refs that are fetched, this won't clone the remotes themselves, which are defined in the repository's git config - git clone doesn't clone anything from .git/config, which is considered to contain private information." may be telling me that what i want is impossible? So I'll have to manually add the remotes again, every time i clone? – Joao Pincho Jun 20 '13 at 15:29
  • @RhiakathFlanders Yes, it looks like at this time what you're trying to achieve is impossible with git. I've repos that have multiple remotes but I always have to add additional remotes myself in the manner I described. (Or really just doing: `git remote add originB ssh://git@hostsomewhere.org/username/ur-repo.git` – unknownprotocol Jun 21 '13 at 21:44