Version Control System, IntelliJ IDEA, Create a Git Repository for a Project and push to multiple remotes

A Usage Sample and Notes

Let's focus on how would you switch Git remote repository? or adding multiple remote repository to sync with local branch,

Use cases: if you want to switch GitHub to GitLab or from GitLab to GitHub services.

if you want to add both GitHub and GitLab to sync with your local projects.

We can follow bellow steps in IntelliJ IDEA:

  1. Menu VCS > Enable Version Control Integration
    • This will create/add git system to local driver/disk
  2. After Commit to local branches
    • Usually we allready have lots of files, and historical commits...
  3. Menu VCS > Git > Remotes
    • add renew remote, so new remote repository is connected.
    • named initial: origin,  Now we could adding multiple remote origin, I.e. origin_gitlab...
    • Please Note: we can add multiple remotes as desired.
  4. Menu VCS > Git > Fetch
    • got sync from remote repositroy, but not yet merge with your local branches.
    • Now local and remote repository and commit is all in local driver, under git control, ready for next action.
    • Note: if we have multiple Remotes, the tool will try to fetch remote branches and commits one by one, and ignore anyone if it failed to fetch(Let's say one of the Account is closed)
  5. Menu VCS > Git > Branches > New Branch
    • Now depends on which local branch we currently working on, we can merge or push local commits to remote branches; in my example, I will create a new Local Branch(I.e. SynctoGitLab) from master, and push it to gitlab remote repository.
    • New Branch, will create a local new branch and contains all of the files and commits of 'master'(usually)
  6. Menu VCS Git > Push
    • NOW we can control how and where to push to, means to control push local new branch to which remote repository.
    • [Push commits to ***] In the left hand of the window, selected the local new created branch means which local branch to sync from.  "SynctoGitLab -> origin : SynctoGitLab" new
    • Click on origin to chose the desired remote(git repository), i.e. new added remote: origin_gitlab.
    • so Now it becomes: "SynctoGitLab -> origin_gitlab : SynctoGitLab" new
    • that means it will sync/push local branch "SynctoGitLab" to remote "origin_gitlab" new branch "SynctoGitLab", yes, it will create a new branch and sync with the local branch; now everything got in sync.
    • We can operat Push again and push it to another remote(and so another same naming branch)

Share learning informations:

IntelliJ IDEA. Adding a Project to Git and GitHub

Using Git in IntelliJ

原文地址:https://www.cnblogs.com/backuper/p/Version_Control_System_Create_Git_Repository_push_to_multiple_remotes.html