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 remote -v
origin [email protected]:skela/awesomeproject.git (fetch)
origin [email protected]:skela/awesomeproject.git (push)
upstream git://github.com/bob/awesomeproject.git (fetch)
upstream git://github.com/bob/awesomeproject.git (push)
Is there any way to have this additional remote persist across clones? Say I delete my local repository and do a:
git clone [email protected]:skela/awesomeproject.git
And now I recheck my remotes:
$ git remote -v
origin [email protected]:skela/awesomeproject.git (fetch)
origin [email protected]:skela/awesomeproject.git (push)
My upstream remote has vanished!
How to I ensure that my git repo always keeps these 2 remote aliases?
Edit: Just adding the main reason why I want to do this as to shape some of the answers down an acceptable path ;)
Goal is to have a branch in my repo that tracks the upstream's master.
[remote "upstream"]
url = git://github.com/bob/awesomeproject.git
fetch = +refs/heads/*:refs/remotes/upstream/*
[branch "father"]
remote = upstream
merge = refs/heads/master
In other words, the branch "father" which is in my repo tracks the remote called upstream's master branch.
It all works great once I set it up, but as soon as I clone the repo again, the "father" branch points to origin instead of the upstream.
You can add multiple remotes by using git remote or git config commands or editing the config file. As git can group multiple remotes, you can follow any of the following ways to configure multiple remotes to push simultaneously(no need all). You can set multiple remote URLs to a single remote using git remote.
1 Answer. git fetch --all and git pull -all will only track the remote branches and track local branches that track remote branches respectively.
The git remote command is essentially an interface for managing a list of remote entries that are stored in the repository's ./. git/config file.
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 [email protected]: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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With