Setting Up Version Control
Version control is an important process for managing revisions you make to your files. There are various version control systems (VCS) that help users maintain a record of their revisions.
In this section, you will be setting up version control using a system called Git. Please ensure that you have Git installed prior to executing the following steps.
Through Git, you can initialize a project storage location, or a repository that will maintain a history of project file revisions over time.
Each time you commit your work for a file through Git, there will be a new version of the file recorded in your version history. Each version has a distinct ID and indicates the user that made the commit. If you only commit changes through Git, they will only be recorded in your local machine. When you push your changes, the commits that you made through Git will be reflected on your online GitHub too.
This section will take you through the steps of creating a Git repository for a new project, connecting it to GitHub, and committing and pushing your project changes in IntelliJ IDEA.
Table of Contents
Configuring Git Version Control for a New Project
This sub-section will go through the steps for creating a new IntelliJ IDEA project folder and a Git repository for the new project. This sub-section will also cover the steps for sharing the newly created project repository on GitHub.
- Open IntelliJ IDEA on your computer.
On Mac, you can do this by clicking the Launchpad icon on the Mac dock.
This will open the “Main Window” of IntelliJ IDEA. You should see the welcome screen like the one displayed below.
- Click [Create New Project] which should direct you to a “New Window”.
- Check that Java 13 is added to the ‘Project SDK’ field.
- Click [Next] > [Next].
- Name your new project in the ‘Project Name’ field in the “New Project Window”.
- Click [Finish]. This should take you to the following “Main Window” with your new project open.
- Click [IntelliJ IDEA] > [Preferences] in the toolbar on the top of your screen.
The “Preferences Dialog Window” should appear.
Note: If you have your “Main Window” in full screen mode, you may need to hover over the top of your computer screen to see the toolbar. - Click the dropdown icon next to [Version Control] > [Git] in the left sidebar.
- Check that the path to your Git executable is added.
- Click [GitHub] in the same dropdown menu > [Add account].
A “Log In to GitHub Dialog Window” will appear. - Enter your GitHub username and password in the ‘Login’ and ‘Password’ fields.
- Click [Login].
If your login is successful, the “Log In to GitHub Dialog Window” will disappear and return you to the “Preferences Window”. - Click [OK]. You should now return to the “Main Window”.
- Click [VCS] in the toolbar located at the top of your screen > [Import into Version Control] > [Create Git Repository].
A “Finder Dialog Window” will appear. - Check that your correct project folder is selected.
- Click [Open].
When your Git repository is successfully created, a tab called ‘Version Control’ should appear at the bottom-left side of the “Main Window”.
‘Git’ button options should also appear at the top-right of the “Main Window”.
- Click [VCS] > [Import into Version Control] > [Share Project on GitHub].
A “Share Project on GitHub Dialog Window” will display. You can check or uncheck the box next to ‘Private’ depending if you want your project repository to be private or public on GitHub. - Click [Share].
An “Add Files for Initial Commit Dialog Window” will be displayed. - Select the files that you want initially added to your GitHub project repository.
The .idea files do not need to be added.
You can edit the message in the ‘Commit Message’ field.
- Click [Add].
At the bottom-right of your screen, you will see a message similar to the following image.
Upon completion of these steps, you can now see your new repository on GitHub. You can now create files in your new project in the IDE and add them to your Git repository.
Tracking Changes You Make to Your Work
When you have a new Git project repository and some files that you are working on, there may be changes that you want to save. This sub-section will present steps for making commits and pushing commits in your IntelliJ IDE.
- Click [VCS] > [Commit].
A “Commit Changes Dialog Window” will display. - Select all the source files with changes that you want committed.
- Write a commit message in the ‘Commit Message’ input field that describes the changes you have made to the selected files.
- Select whether you want to commit or commit and push your changes.
- Click [Commit] if you want your commits to be made only on your local computer.
- Select the dropdown icon next to [Commit] and click [Commit and Push] > [Push] if you want your commits published to GitHub.
You can now visit your GitHub account and navigate to your project repository to see the commits that you have pushed.
Upon completion of these steps, you now have an understanding of how to regularly capture the current state of your work through Git.