Step 1: Initialize a Git Repository
- Open your project in IntelliJ IDEA.
- If you haven't already initialized your project as a Git repository, - go to VCS > Enable Version Control Integration from the top menu.
- Choose Git from the list and click OK.
Step 2: Commit Your Project to the Local Repository
- Go to VCS > Commit (or use the Ctrl+K shortcut).
In the Commit Changes dialog, select the files you want to commit. It's a good practice to review the changes and ensure temporary or unnecessary files (like build outputs) are not included. IntelliJ's .gitignore file can help with this.
- Write a commit message that describes the changes you're making.
- Click the Commit button. You can choose Commit and Push if you're - ready to push your changes directly after committing, but assuming this is the first commit, just a commit is sufficient for now.
Step 3: Create a New Repository on GitHub
- Go to GitHub and log in.
- Click on the + icon in the upper-right corner and select New repository.
- Name your repository, add a description if you want, and decide if you want the repository to be public or private.
- Click Create repository. Do not initialize the repository with a README, .gitignore, or license. Since you're pushing an existing project, you'll want to leave the repository empty.
Step 4: Link Your Local Repository to GitHub
- Inside the terminal, type the following command to add the GitHub repository as a remote to your project:
* Replace <REPOSITORY_URL> with the URL you copied from GitHub.
git remote add origin <REPOSITORY_URL>
Step 5: Push Your Project to GitHub
Still in the IntelliJ Terminal, push your project to GitHub with the
git branch -M main
git push -u origin master