Git Multiple Remote Repository Configuration

· 1 min read

In actual development, sometimes you may encounter situations where Git projects need to be hosted on multiple remote addresses. Fortunately, Git supports multiple upstreams, so the operation is quite simple.

Example

For example, we have GitHub and Gitee (formerly known as 码云) repository addresses

# Add GitHub
$ git remote add github https://github.com/alanhe421/NiceFish.git

# Add Gitee
$ git remote add oschina https://gitee.com/mumu-osc/NiceFish.git

# Push to GitHub
git push github master

# Push to multiple repositories
git push --all 

Syntax Explanation

For detailed information, please refer to the official manual: Link

# name is the remote name, url is the address
$ git remote add  <name> <url>

# --all, push all branches, repository is the repository address or remote name, refspec is the branch name
$ git push [--all] [<repository> [<refspec>…​]]