Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Able to push to all git remotes with the one command?

Tags:

git

People also ask

Does git push to all remotes?

You cannot pull from multiple remotes, but you can fetch updates from multiple remotes with git fetch --all .

How do I push all remote branches?

To push the all branches to remote git, we can use the git push command followed by the --all flag and origin.

Which command allows pushing all the branches to remote repository?

The git push command allows you to send (or push) the commits from your local branch in your local Git repository to the remote repository. To be able to push to your remote repository, you must ensure that all your changes to the local repository are committed.


Create an all remote with several repo URLs to its name:

git remote add all origin-host:path/proj.git
git remote set-url --add all nodester-host:path/proj.git
git remote set-url --add all duostack-host:path/proj.git

Then just git push all --all.


This is how it looks in .git/config:

  [remote "all"]
  url = origin-host:path/proj.git
  url = nodester-host:path/proj.git
  url = duostack-host:path/proj.git

To push all branches to all remotes:

git remote | xargs -L1 git push --all

Or if you want to push a specific branch to all remotes:

Replace master with the branch you want to push.

git remote | xargs -L1 -I R git push R master

(Bonus) To make a git alias for the command:

git config --global alias.pushall '!git remote | xargs -L1 git push --all'

Running git pushall will now push all branches to all remotes.


If you want to always push to repo1, repo2, and repo3 but always pull only from repo1, set up the remote 'origin' as

[remote "origin"]
    url = https://[email protected]/path/to/repo1
    pushurl = https://[email protected]/path/to/repo1
    pushurl = https://[email protected]/path/to/repo2
    pushurl = https://[email protected]/path/to/repo3
    fetch = +refs/heads/*:refs/remotes/origin/*

Configure at command line:

$ git remote add origin https://[email protected]/path/to/repo1
$ git remote set-url --push --add origin https://[email protected]/path/to/repo1
$ git remote set-url --push --add origin https://[email protected]/path/to/repo2
$ git remote set-url --push --add origin https://[email protected]/path/to/repo3

If you only want to pull from repo1 but push to repo1 and repo2 for a specific branch specialBranch:

[remote "origin"]
    url = ssh://[email protected]:7999/yyy/repo1.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    ...
[remote "specialRemote"]
    url = ssh://[email protected]:7999/yyy/repo1.git
    pushurl = ssh://[email protected]:7999/yyy/repo1.git
    pushurl = ssh://[email protected]:7999/yyy/repo2.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    ...
[branch "specialBranch"]
    remote = origin
    pushRemote = specialRemote
    ...

See https://git-scm.com/docs/git-config#git-config-branchltnamegtremote.


As a CLI Alternative to editing the .git/config file, you could use the following commands:

# git remote add all origin-host:path/proj.git
# git remote set-url --add all nodester-host:path/proj.git
# git remote set-url --add all duostack-host:path/proj.git

The same git push all --all works here as well.

You have accomplished the same as answer #1. You have just done it with Command Line instead of raw editing of the config file.