Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Step 4: Git(Hub) Integration

Gremious edited this page Jun 4, 2019 · 11 revisions

Time to setup a Version Control System!

Setting up VCS with intelliJ is actually pretty simple (even if I have made this guide rather wordy) and will highly benefit you in the long-run. Not only with modding, but with general coding, no matter what/where you code. We'll be using Git + GitHub.

Official Documentation for extra help:

https://www.jetbrains.com/help/idea/set-up-a-git-repository.html

https://www.jetbrains.com/help/idea/github.html


Step 0: Create a GitHub account

If you don't have one already, go ahead and create a GitHub Account (https://github.com/join).

Step 1: Download and Install git

We can't use git if we don't have it, so hop on over the the git website and download the latest version for your OS.

You can leave every setting at default and just press next until you hit install, however, please take a note of 2 things:

  1. Make sure that this setting is selected when you reach it:

enter image description here

  1. Note the installation path, as we'll need it later.

You can also select a different text editor for git related files (like notepad++ or whatever you like to use) if you want, when you reach that setting.

Step 2: Point IntelliJ to your Git installation

Open up the settings (Ctrl+Alt+S) and type in git in the settings search bar.

In the Path to Git executable, Point IntellIJ to git.exe, which will be where you installed Git.

enter image description here

You can press the Test button to make sure it works.

enter image description here

Step 3: Point IntelliJ to your GitHub Account

While we're here, press the GitHub button just bellow Git on the left hand side.

Press the Plus button on the left, and login to your GitHub account.

enter image description here

Step 4: Gitignore

Before we start a repo, we'll need a .gitignore file. By default, git will want to keep track of every single file in the project directory. This can get unnecessarily messy if it starts tracking all your intelliJ project settings/maven option files/etc, as it makes it increadibly easy to accidentally push (read: upload) those unnecessary files to GitHub, cluttering your project.

The Default comes with a the standard GitHub-provided java gitignore, with 1 added line to exclude spriter autosave animation files. If you're curious, you can see the list of which files it ignores by opening it in any text editor. Of course, you can also edit it if you want (for exmaple, you can exclude psd files from being under version control (and with that, likely uploaded to GitHub) by adding *.psd to it).

To add that .gitignore file to your mod, just copy and paste from the root folder of the default (You'll find it next to the README.md and LICENSE files) to theDefault folder, or whichever folder has has your pom.xml in it.

Step 5: Setting Up a Local Repository from IntelliJ

In the top menu, select VCS > Enable Version Control Integration...

enter image description here

Select Git and press OK.

enter image description here

Congratulation, you have a local repoistory!

You can start commiting changes to it via one of three ways:

  1. Openining the terminal by pressing Alt+F12 (I have mine bound to Alt+` for quick access)
  2. The quick-access buttons in the top right of the screen

enter image description here

  1. Double-tapping shift and typing Commit (Or any other command you need).

In order to make sure everything is correct at a glance, let's use step 2 or 3. It will open up the following window:

Checkbox all Unversioned Files

enter image description here

Make sure your .idea folder or any files from it aren't present here (If they are, retrace your steps in regards to the .gitignore).

If it isn't, just write the Initial Commit message and press Commit!

This message box will likely pop-up every time you commit , simply press Commit to continue.

enter image description here

Same with the following TODO pop-up.

Step 6: Setting Up a Remote Repository on GitHub

Sharing a new project on GitHub is pleasantly simple with IntelliJ.

From the top menu, select VCS > Import into Version Control > Share Project on GitHub

enter image description here

Give it a nice name and a temporary description. If you don't want it to be visible by others, you can tick Private, however, keep in mind that sharing your code with others when you need help from #modding for debugging will be harder.

enter image description here

Wait for it to create your new repo and push all the files!

enter image description here

Step 7: Commiting, Uploading and Sharing Files and Changes.

Save early, save often! A commit is a snapshot of your code. Through them, you can review your code history, and reset back if you screw up. There's no such thing as too-small of a commit, as they help track and revert individual changes. Always commit before and after big changes too, such as mass-refactors, in case they break lots of unexpected things!


Let's imagine you made a new card, (or part of a card (or even just added a comment you deem is good enough to deserve it's own commit)).

When you create a new file, IntelliJ will ask you if you want to add it to Version Control

enter image description here

You can press Add, and changes to that file will start being tracked.

(You'll notice that new files are highlighted in green, while changed ones already under VCS in blue. If you find a color you want to know about, you can read about them here if you'd like.)

Once you want to commit some changes, the fastest way is to simply press Alt+F12 (Though I do recommend binding that to something faster/nicer like Alt+ ` ) to open the terminal and type

git commit -am "Added my cool card, or whatever your nice and descriptive commit message is"

You can just do that every time you want to commit, which saves you from going through intelliJ's gui loading and multiple confirmation pop-ups.

If you want to upload your changes to your GitHub repo, simply open the terminal and type git push - done, your changes are uploaded!

You can share your code by browsing and linking it directly from your GitHub, or, by right-clicking an opened file you wish to share and pressing Open on GitHub.

enter image description here

You can also create Gists of any selected file or code, in order to share ether the whole file or code snippets.