Reputation: 6984
I have several remotes with different push
configurations; e.g.
[remote "public"]
url = ssh://external-server/repo
push = refs/heads/master:refs/heads/master
[remote "internal"]
url = ssh://internal-server/repo
push = refs/heads/*:refs/heads/*
Is it possible to push to both repositories with a single, simple command without inventing additional layers?
I tried pushUrl
as suggested in related questions but this expects an url and does not allow a remote. Then, I modified it to use git-remote-ext
like in
[remote "all"]
pushUrl = "ext::git push public"
pushUrl = "ext::git push internal"
But this pushes to the first repository only and fails then with
fatal: Could not read from remote repository.
Manual shell commands (git push public && git push internal
) are not a solution because in reality I have a lot of repositories which are having different sets of remotes (e.g. git servers hosted by customers, public repositories, internal/external mirrors, test systems, read-only sources). Sometimes they are in submodules which I want to push in a way like
git submodule foreach 'git push all'
Defining an alias might work but is too clumsy and breaks somehow the usual workflow (using git push
to push things).
Upvotes: 2
Views: 312
Reputation: 1323753
The related question should be "Git - Pushing code to two remotes", and it involves a remote 'all
' with push urls.
ext::git push public
is not an url. ssh://external-server/repo
is.
git remote rm all
git remote add all ssh://internal-server/repo
git remote set-url --add --push all ssh://internal-server/repo
git remote set-url --add --push all ssh://external-server/repo
By default, it will use the push refspec refs/heads/*:refs/heads/*
If you set your default push policy to upstream, only branches which have an upstream branch will be pushed.
git config push.default simple
~
Upvotes: 1