问题
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?
回答1:
Here is a good example it worked for me
...
For example, here are the remotes specified in my .git/config file:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = /Users/loki/sandbox/git/parent
[remote "github"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:jbklikh/git_test.git
...
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206722225-how-to-specify-multiple-remote-repositories
回答2:
modify .git/config add mirror code...
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = http://JungleYang@192.168.10.96:18080/r/upflow.git
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://JungleYang@192.168.10.189:18080/r/upflow.git
fetch = +refs/heads/*:refs/remotes/mirror/*
[branch "master"]
remote = origin
merge = refs/heads/master
回答3:
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).
- Add a second remote repository
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…
- Copy the link of the repository2 by going to your GitLab (I was using BitBucket), selecting your project, clicking on Clone, and copying the URL.
- Click on a plus, name the remote (eg. origin-copy, in my case work-in-progress) and provide the link to the repository2. Click OK.
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.
- When you’re done with selecting the repository (we named repository2 origin-copy) and the branch we want to push to (in our case develop) you can press the button Push.
来源:https://stackoverflow.com/questions/25665926/pushing-into-multiple-remote-repositories-simultanously-in-intellij