9

I wish to use git with multiple remote repos. I have my central git server (aka origin), as well as my local dev machine. What I am trying to do is pull down the latest linux kernel from kernel.org's git repo. I will then make a few changes, and then push the whole modified repo up to my own git server.

I have managed to do this ok (by just doing git remote add a couple of times - ones for the origin and once for kernel.org). However, if I clone origin from scratch, I am unable to see kernel.org as a remote.

Is there a way to push the remote add commands? Or is it that everytime I wish to pull in changes from kernel.org (on a new machine), do I have to manually add it?

Also, when I create my local branch, I made it track a remote branch from kernel.org. Since I can't see kernel.org as a remote on a fresh clone, does this mean that this branch isn't tracking kernel.org anymore?

Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
jtnire
  • 1,348
  • 5
  • 21
  • 32

4 Answers4

4
git push origin --mirror

will push all local refs to origin.

Rostyslav Dzinko
  • 39,424
  • 5
  • 49
  • 62
2

If you clone each time, you will lose what you have in the configuration of that repo. This includes reflog, stash, remotes and rerere cache just to name a few. Don't do this. Pushing and pulling does not move these artefacts. All you get from pushing and pulling is references and the objects needed to satisfy that. Remote settings don't get propagated. Clone is a once per repo operation. You can actually not use clone at all. You can make an empty repo with git init then add the remote manually with git remote add and then git fetch.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • The reason why we need to do a clone is because multiple developers have access to this repo. Does that mean that each individual developers has to add a remote manually for kernel.org if they wish to pull down changes from there? – jtnire Aug 18 '12 at 22:38
  • That is no reason to reclone. You can have one repo that pulls from kernel.org and others pull from that repo. Or, have each dev add the kernel one. – Adam Dymitruk Aug 18 '12 at 23:48
  • I'm sorry I don't quite understand how this answer the question. You've stated why we don't have to use clone, but you haven't answered the question. The issues lies in the fact that the standard push command doesn't send up the remote config. This means that no-matter what the other devs use to get the repo from origin, they still won't have the remotes. – jtnire Aug 19 '12 at 11:04
  • pushes will NOT send the config. Recloning will always wipe any remotes you have set up. – Adam Dymitruk Aug 19 '12 at 17:56
  • Yes, I'm aware of that, hence this question :) Is there anyway to achieve this though? Is the only solution to just manually share the git config file? – jtnire Aug 19 '12 at 20:57
  • 1
    There may be a way to do so with git attributes and custom scripts. But this always has to be kicked off with the user doing something. This has to do with security. By committing something you should not be able to affect where someone else's machine is going to connect to. – Adam Dymitruk Aug 20 '12 at 03:56
0

As stated in the other answers, what I'm trying to do can't really be done in Git (sharing remotes). So what I intent to do is to avoid the need for 3rd party remotes on the developer machines. I will create a local branch that is identical to the kernel.org remote branch. I will then push this local branch to my git server (origin). I will then create a cron script that will:

  • Clone the branch that I created above.
  • Add a remote for kernel.org
  • Do a git pull to update the branch
  • Add, commit and push

This means I'll have a copy of the kernel.org branch on my own git server, which can be tracked as normal within our local team. All merges can then proceed as normal...

What you think?

Thanks

jtnire
  • 1,348
  • 5
  • 21
  • 32
  • Also, assuming I keep the copy of the cron repo on the server, i won't need to clone or add a remote in the cron script - this only needs to be done the first time. – jtnire Aug 20 '12 at 17:18
0

It's not exactly possible to "share remotes". However you might try this.

  1. Put a shell script in the root (or scripts/) directory of your repo. Call it, for instance, git-bootstrap.

  2. In the script, add the remotes, like so:

    #!/usr/bin/env bash

    git remote add upstream git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

    # Note that you do not need to add the origin remote as that is set up when you clone.

  3. After cloning on a new machine, run the git-bootstrap script.

Steven Shaw
  • 6,063
  • 3
  • 33
  • 44