tags:

views:

42

answers:

2

I am setting up a Git repository. I know you can add repositories using git config --global, but is there a way that those known repositories gets cloned by users?

The goal would be that once the repo gets cloned by userz, they can push to other repos just by their aliases.

For example, I add git://X/mobility.git as X to the repo (somehow), a user clone it from git://Y, but then can do git push X without previously doing the git config.

How to do that?

+2  A: 

I don't believe Git supports this. Repository aliases are individual to the local machine and not part of the cloning process.

Amber
+1  A: 

Amber is right. The configuration of remote entries is not cloned along with the rest of the repository (nor is any other repository specific configuration data).

You might consider including (in the tracked content of the repository) a script to setup the remotes. End users could run this script to create the remotes. The script can not, however be run automatically since it would introduce security problems (cloning a repository should be a safe operation; it would not be a safe operation if Git automatically ran some script/binary that it just downloaded).

Incidentally, it might be easier using git remote to manage the remotes instead of git config.

add_or_update() {
    if git config remote."$1".url >/dev/null 2>&1; then
        git remote set-url "$1" "$2"
    else
        git remote add "$1" "$2"
    fi
}
add_or_update foo [email protected]:foo.git
add_or_update add bar git://other.example.com/dev/bar.git

If you are using a non-standard fetch refspec, you may need to use git config, since git remote does not (yet) support managing a remote's refspec(s).

Chris Johnsen