I have a git repo that is a fork of another repo. As a rule I will normally add a remote called upstream, which is the original repo I forked from.
$ git rem
That is impossible. Git only clones the repo’s content, never its settings. If your want to hard-wire remotes into your repo (it stands to question whether that is a good idea), create a script repo-setup.sh
in your repo root that does something like this:
git remote rm origin
git remote rm upstream
git remote add origin git@github.com:skela/awesomeproject.git
git remote add upstream git://github.com/bob/awesomeproject.git
Then run this file after you cloned the repository.
Create a file .gitremotes that you populate with the content of .git/config related to remotes. Add .gitremotes to the repository. After the clone append .git/config with .gitremotes. Note: might need some hand editing if the remotes that you want to share (in .gitremotes) have a name conflict with the remote that 'git clone' creates automatically ('orgin').
To accomplish this easily you could define a bash function:
function git-clone-r ()
{
src=$1
tgt=$2
git clone $src $tgt
cat ${tgt}/.gitremotes >> ${tgt}/.git/config
}
[The above isn't all that sophisticated; but illustrates the point and works]
This is a slightly modified version of GoZoner's solution.
You need to capture the info about all the remotes from your repo's .git/config
into a file that you could store outside your git repository. You also need to take care of updating this file every time you add a new remote. This can in fact be added to your git repo, so that the next clone or pull brings in this file.
Starting with git 1.7.10+
, git supports including external config files.
So you can add the following lines to your repo's .git/config
to include the external config file containing the remote info:
[include]
path = /dir1/dir2/repo-remotes.gitinfo