CSE 373, Spring 2019: Intro to Git, Part 1

Locating your GitLab repository

In this class, the remote repositories on GitLab will be created for you beforehand with the starting code. When we create your repo, GitLab should send you an email with a link to the repo; you should also be able to find your repository by navigating to the GitLab link in the navigation bar of this site, which will take you to the GitLab group that contains all your repositories for the quarter (along with public repositories containing the starter code, which you may ignore).

Obtaining the repository

Once you've found your repo on GitLab, you'll need to clone that remote repo to get a copy on your own machine. Anyone already familiar with Git may use Git's command line interface or any other UI, but we'll use IntelliJ's Git UI in this guide. (If you opt to use another method, note that the course staff may not be able to debug any issues you encounter.)

  1. If IntelliJ is open on the welcome screen, you can just click "Check out from Version Control" option.

    Otherwise, if a project is already open, you can click "VCS" > "Checkout from Version Control" > "Git".

  2. Afterwards, a window will open where you should enter the URL of your repository from GitLab and a directory to save the cloned repo into.

    Note that this URL is NOT just the URL of the webpage you visit; instead, get this URL by navigating to the home page of your repository on GitLab ("Project" > "Details"), then clicking the copy button on the right side of the text box labelled "SSH". The URL should look somewhat like the one in the image above. (If the text box is labelled "HTTPS" instead, you'll need to click the dropdown to select "SSH" before copying the URL.)

    (If you do not have a repo: for homework 1, you can clone this public repo. You will not be able to push (submit) until you have your own personal repo, however. If you're enrolled in the class but do not have a repo made for you, you should fill out this form to notify us.)

  3. After the previous step, IntelliJ should have downloaded the repo onto your machine. If you've cloned the repo correctly, IntelliJ should also be able to tell that the code you just cloned contains a project that it can import, so it should pop up with another window asking whether you want to open it now.

    It should be safe to choose "Yes" here to import and open the project. (More details on exceptions later.)

  4. Make sure that "Gradle" is selected on the next screen, then click "Next"

  5. Make sure that "Use auto-import" is checked and that "Use gradle 'wrapper' task configuration" is selected, then click "Finish".

Afterwards, IntelliJ will import and open the project. Note that it will also attempt to download any other libraries needed for the project, so make sure you remain connected to the internet while it finishes.

What if my project doesn't import properly?

Sometimes, in partner projects, your partner may accidentally commit their IDE configuration files. These files sometimes include absolute file paths which, when transferred between machines, will cause your IDE configuration to break. There are also other cases where the initial import simply doesn't work, for some reason or another.

In these cases, you should re-import the project:

  1. If you still have the project open, close it by clicking "File" > "Close Project". This should bring you back to the welcome screen, from where you should click "Import Project":

    Alternatively, if you had another project open instead, simply click "File" > "New" > "Project from Existing Sources...":

  2. Navigate to and select the folder containing the code, and then click "OK". There should be a build.gradle file directly inside that folder. (You may also select the build.gradle file instead if using the folder doesn't work.)

  3. From here, continue importing the project as shown starting in steps 4 and 5 above.

What is a 'gradle project'?

When working on larger projects, programmers tend to face a few different problems:

  1. How do you keep track of what 3rd party libraries the project needs installed?
  2. Each IDE stores its project config in a slightly different way. How can you make sure your project can run on all kinds of different IDEs, including ones you've never heard of, with minimal fuss?
  3. Sometimes, building our project and producing a final JAR we can give to our users can require running multiple instructions/performing several complex steps. Instead of having to do that manually, can we just write a script that does this all automatically for us?

It turns out that we can use the same tool to answer all of these questions: a build manager. Basically, what happens is that we record all of the libraries we need, all project configuration, and all build instructions inside of a special file our build manager understands.

Conveniently, it also turns out that all (modern) IDEs have great support for a wide variety of popular build managers: they can read the special file and automatically convert all of those instructions into their IDE-specific configuration.

In our case, we're using a build manager called "gradle". Try opening up build.gradle inside of your project. If you skim through it, you can see that the file configures a variety of things and specifies a handful of 3rd party libraries we want to install and use. (We've commented this file fairly heavily in case you're curious).

Gradle isn't the only Java build manager—other popular build managers include Ant, Maven, and Ivy.

If you start working with other programming languages, you'll learn that they all also have their own build managers and conventions for managing large projects. However, at a high level, they all work in the same way: you specify the libraries you need and your build instructions in some file(s), and run some sort of build tool to manage everything for you.