Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing into multiple remote repositories simultanously in IntelliJ

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?

like image 967
snakile Avatar asked Sep 04 '14 12:09

snakile


People also ask

Can Git push to multiple remotes?

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.

Can we have more than one remote repository to track?

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 .

How do I push to a different branch in IntelliJ?

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.


2 Answers

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).

  1. 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…

add remote menu item

  1. 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.

BitBucket clone repository

  1. 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.

remote dialog

  1. You should now see the new repository – repository2 added to the list of Git remotes

  2. In the menu, go to VSC → Git → Fetch. This way you make sure you have access to all the repository2 branches.

  3. Git commit and push Push the current repository1 branch to repository2 branch:

    Press Ctrl+shift+k (or go to VSC → Git → Push…)

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.

  1. 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.
like image 55
fan Avatar answered Sep 20 '22 14:09

fan


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
like image 33
Jungle Avatar answered Sep 17 '22 14:09

Jungle