Link

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

  1. Configuring Git Version Control for a New Project
  2. Tracking Changes You Make to Your Work

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.

  1. 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.
    IntelliJ IDEA welcome screen
  2. Click [Create New Project] which should direct you to a “New Window”.
  3. Check that Java 13 is added to the ‘Project SDK’ field.
    Project SDK field
  4. Click [Next] > [Next].
  5. Name your new project in the ‘Project Name’ field in the “New Project Window”.
    Project name field
  6. Click [Finish]. This should take you to the following “Main Window” with your new project open.
  7. Click [IntelliJ IDEA] > [Preferences] in the toolbar on the top of your screen.
    Toolbar 1
    The “Preferences Dialog Window” should appear.
    Note icon 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.
  8. Click the dropdown icon next to [Version Control] > [Git] in the left sidebar. Sidebar 1
    Sidebar 2
  9. Check that the path to your Git executable is added. Git executable field
  10. Click [GitHub] in the same dropdown menu > [Add account].
    Add GitHub account
    A “Log In to GitHub Dialog Window” will appear.
  11. Enter your GitHub username and password in the ‘Login’ and ‘Password’ fields.
  12. Click [Login].
    If your login is successful, the “Log In to GitHub Dialog Window” will disappear and return you to the “Preferences Window”.
  13. Click [OK]. You should now return to the “Main Window”.
  14. Click [VCS] in the toolbar located at the top of your screen > [Import into Version Control] > [Create Git Repository].
    Toolbar 2
    A “Finder Dialog Window” will appear.
  15. Check that your correct project folder is selected.
    Finder window
  16. 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”.
    Version control tab
    ‘Git’ button options should also appear at the top-right of the “Main Window”.
    Git button options
  17. 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. Share Project on GitHub
  18. Click [Share].
    An “Add Files for Initial Commit Dialog Window” will be displayed.
  19. Select the files that you want initially added to your GitHub project repository.
    The .idea files do not need to be added.
    Add Files for Initial Commit Dialog Window
    You can edit the message in the ‘Commit Message’ field.
    Add Files for Initial Commit Dialog Window 2
  20. Click [Add].
    At the bottom-right of your screen, you will see a message similar to the following image. Notification

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.

  1. Click [VCS] > [Commit].
    Toolbar 3
    A “Commit Changes Dialog Window” will display.
  2. Select all the source files with changes that you want committed.
    Commit Changes Dialog Window 1
  3. Write a commit message in the ‘Commit Message’ input field that describes the changes you have made to the selected files.
    Commit Changes Dialog Window 2
  4. 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.
      Commit and Push button
      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.