Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add an existing IntelliJ Java project to git?

This question is similar to this one for Eclipse but with a different IDE.

How can I add my pre-existing Java to git in IntelliJ IDEA?

Current State:

  • Existing Spring Boot Project initialized from start.spring.io
  • Newly created GitHub repository

I could check out the new repository, copy the contents of my project to this directory and just push to master, but is there a simpler way within the IDE that avoids changing the location of the project?

like image 694
Neeraj Jain Avatar asked Mar 14 '19 08:03

Neeraj Jain


People also ask

How do I push a Java project from IntelliJ to GitHub?

Do one of the following: 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.

How do I add an existing repository to Git?

In the command line, navigate to the root directory of your project. Initialize the local directory as a Git repository. To create a repository for your project on GitHub, use the gh repo create subcommand. When prompted, select Push an existing local repository to GitHub and enter the desired name for your repository.


2 Answers

  1. Go to VCS > Import into Version Control > Create Git Repository
  2. Then go to VCS > Git > Remotes
  3. Click the + button, leave origin as-is and paste the Git URL of your repository
  4. VCS > Git > Git Pull then VCS > Git > Git Push
like image 127
Vinz243 Avatar answered Sep 19 '22 05:09

Vinz243


'VCS' on the menu bar > 'Import into Version Control' > 'Create Git repository...'


To hopefully somewhat future-proof this answer in case the location moves, you can use:

CtrlShiftA (or CommandShiftA on a Mac) to open the action search dialog and search for 'create git'.

like image 23
Michael Avatar answered Sep 18 '22 05:09

Michael