Context
You want to working with multiple Git repositories on one local source code.
Config
For example: There are 2 repos
- Github: git@github.com:PhuSanh/test-a.git
- Gitlab: git@gitlab.com:dpsanh2348/test-b.git
Assuming that you already have github repo on your local machine
1
git clone git@github.com:PhuSanh/test-a.git
Option 1: Config 1 remote for multiple repos
- Create a new git remote
all
1
git remote add all git@github.com:PhuSanh/test-a.git
- It can be any name
- Origin remote can be used as well
- Register your push URLs
1 2
git remote set-url --add --push all git@github.com:PhuSanh/test-a.git git remote set-url --add --push all git@gitlab.com:dpsanh2348/test-b.git
Result
- CHECK:
git remote -v
- PUSH: Now you can push to 2 repos at the same time
1
git push all <your branch>
- PULL: can not pull from multiple remotes
- FETCH: can fetch all with
git fetch --all
Option 2: Config multiple remotes for multiple repos
- Add new remote with
gitlab
andgithub
name Note: we can use existingorigin
remote for github1 2
git remote add github git@github.com:PhuSanh/test-a.git git remote add gitlab git@gitlab.com:dpsanh2348/test-b.git