I'm using git within the IntelliJIDEA IDE. I have two remote repositories to which I would like to push my commits. How do I push to both remotes simultaneously?
It is easy to synchronize code between multiple git repositories, especially, pushing to multiple remotes. This is helpful when you're maintaining mirrors / copies of the same repository. All you need to do is set up multiple push URLs on a remote and then perform git push to that remote as you usually do.
You can set multiple remote URLs to a single remote using git remote. If you don't have a remote named 'all' already, create it using git remote add then use git remote set-url --add to add a new URL to the existing remote. You can cross-check added new remotes using git remote -v .
To push changes from the current branch press Ctrl+Shift+K or choose Git | Push from the main menu. To push changes from any local branch that has a remote, select this branch in the Branches popup and choose Push from the list of actions.
There is a nice blog post which explains how to do this with IntelliJ. It does however not allow for simultaneous push to 2 repositories.
I will shorten the blog content (and copy past the authors text).
Let’s assume we’re working on the code from repository1, already imported to IntelliJ. Add another remote repository, we’ll call it repository2.
In the menu, go to VCS→ Git → Remotes…
You should now see the new repository – repository2 added to the list of Git remotes
In the menu, go to VSC → Git → Fetch. This way you make sure you have access to all the repository2 branches.
Git commit and push Push the current repository1 branch to repository2 branch:
Press Ctrl+shift+k (or go to VSC → Git → Push…)
Select the repository you’d like to push your code to. For example, if your repository1 is named origin and repository2 is named origin-copy, select origin-copy. After that you can also select the branch you’d like to push your code to by clicking on the name of the branch (it will autocomplete the name of the branch as you type it in). You can also type in a name of a new branch, which will be then automatically created in the repository2.
modify .git/config add mirror code...
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = http://[email protected]:18080/r/upflow.git
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://[email protected]:18080/r/upflow.git
fetch = +refs/heads/*:refs/remotes/mirror/*
[branch "master"]
remote = origin
merge = refs/heads/master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With