How to create multiple remote origins

Having multiple remote origins is a common scenario when you want to push your code to multiple Git hosting platforms, such as GitHub and GitLab. Here's how you can set up two remote origins for your Git repository:

  1. Add the first remote origin:

    git remote add origin-github <GitHub repository URL>

     

  2. Push your code to the first remote origin:

    git push origin-github <branch-name>

     

  3. Add the second remote origin:

    git remote add origin-gitlab <GitLab repository URL>

     

  4. Push your code to the second remote origin:

    git push origin-gitlab <branch-name>

     

Note that you can use any name you want for the remote origins, but it's recommended to choose meaningful names that reflect their purpose.

After setting up the remote origins, you can push your code to both platforms by running the appropriate git push command for each origin. For example, if you want to push your code to both GitHub and GitLab:

git push origin-github <branch-name> git push origin-gitlab <branch-name>

Alternatively, you can use Git aliases to simplify the process. For example, you can create an alias called push-all that pushes your code to both GitHub and GitLab:

git config --global alias.push-all '!f() { git push origin-github $1 && git push origin-gitlab $1; }; f'

With this alias, you can push your code to both platforms with a single command:

git push-all <branch-name>

 

If you need assistance with your projects feel free to email me at info@airgad.com or whatsapp Jesse stay safe!