To add a second remote origin to Git and push changes to two repositories on GitHub,follow these steps:
- Use the git remote -v command to list the existing remote origins for the repository. You should see something like this:
git remote -v
- Use the git remote add command to add a second remote origin to the repository. For example, if you want to add a remote origin named “second” with the URL https://github.com/username/second-repo.git, you can use the following command:
git remote add second https://github.com/username/second-repo.git
- Use the git remote -v command again to confirm that the new remote origin has been added:
git remote -v
origin https://github.com/username/repo.git (fetch)
origin https://github.com/username/repo.git (push)
second https://github.com/username/second-repo.git (fetch)
second https://github.com/username/second-repo.git (push)
-
Make any changes to your local Git repository and commit them using the git commit command.
-
Use the git push command to push your changes to both remote origins. To push to both origins at once, you can use the –all option:
git push --all
This will push all branches to both remote origins. Alternatively, you can specify a specific branch to push to both origins:
git push origin branch-name
git push second branch-name
This will push the specified branch to both remote origins.