Loading

7842 Navigators

Introduction to GitHub

Git is a Version Control System. It helps you keep track of your code, monitor changes, and is a standard tool in any programmer’s workspace.

GitHub is an online platform that hosts your Git Repositories in the cloud. It allows you to collaborate with others, share code, and manage your workflow.

Together, these two systems are an incredibly powerful addition to any programming project, as it allows you to manage your code in many great ways.

Here are some of it’s features:

  • Keep track of every change in your code with incremental commits
  • Compare and merge different edits of your code
  • Manage different branches and versions of your code
  • View and restore backups
  • Share code and work with others

Prerequisites

In order to set up GitHub with PROS, we need the following:

  • A GitHub Account – Signup
  • GitHub Desktop – Download
  • A PROS Project Created and Loaded

Methods

There are two ways to create a PROS 3 GitHub repository:

  • Creating a Git repository from an existing PROS 3 project and publishing to GitHub using GitHub Desktop.
  • Creating a GitHub repository on github.com, cloning it to your computer, then creating a PROS 3 project inside that.

Method 2 does not require GitHub Desktop, but we still recommend you install it because it is very useful while managing your code. We will walk through method 1, as most people already have a project to start with.

Uploading an existing PROS 3 project

At this point, we should have the PROS Editor open with a project created.

Creating a local Repository

Before we even deal with GitHub, we have to create a local Git repository. A repository is a location where all the files for a particular project are stored. To create one using the Editor, click on the Git Panel Button on the bottom right of the screen:

Next, Click on Create Repository. In the following dialogue, make sure the path is set to the correct location of your project.

If Git does not show the proper path, make sure your project is open in PROS, a file is open in the Editor, and there are no other project folders open in PROS. Git will look for the uppermost open directory.

Now click Init. A Repository has been created!

Now you can see a list of all your files in the Unstaged Changes box. However, you can see there is a lot of garbage files in that list, notably the .vscode cquery meta files PROS generates. We don’t want to sync these with GitHub.

Creating a .gitignore file

While you want Git to keep track of your source code files, you do not want it tracking all your Compiled Object files, Executable files, and other garbage your compiler and your system may spit out.

To solve this, we use a .gitignore file. This file lets Git know what files to ignore.

By default, Git does not make a .gitignore file. However, I have created one here for you to download. This .gitignore file contains all the standard ignores, but also some pertaining to PROS.

In order to import this file into your project, you have two options. You can either:

  • Download this file into your project directory – right click the link and select Save Link As. You will have to rename the file to be .gitignore
  • Follow the below steps to automatically download this file into your project

Automatic .gitignore download

Open a terminal of your choice inside your project directory. You can either open CMD and navigate to the proper directory, or you can open the terminal inside the Editor. You can also open Explorer and paste the following command directly in the path bar.

Paste and run the following command, which downloads the .gitignore file into your project:

certutil.exe -urlcache -split -f "https://7842navigators.com/wp-content/uploads/2019/01/.gitignore" .gitignore

Hopefully this works. If it doesn’t, use your downloader tool of choice to download https://7842navigators.com/wp-content/uploads/2019/01/.gitignore. Make sure the downloaded file is named .gitignore.

Done! You should now see all the garbage files disappear from the Git panel. You are now ready for your first commit!

Staging the first commit

Now we are able to add the filtered project files into the repository. To do so, press Stage All in the Git panel. This will move all the files into the Staged Changes box. Now type a message in the Commit Message box such as “Initial Commit”, and press the Create Commit button.

You have created your first commit! Now all your project files are inside the repository.

Now, whenever you make a change to a file, it will show up in the Git panel. Make periodic commits to save incremental versions of your code.

Creating a Branch

If you want to modify your code, but you want to make a copy of your original code to revert to, or you want to separate your code into different paths, you can make a branch.

A branch is an alternate version of your code. Branches work by looking at the origin of the split and calculating commits from that point.

Here is an example of the use of branches: You have a driver code for a robot. You decide you want to make an alternate version of your code for a different robot. So you make a new branch, and name it “Code B”. You take this code, switch up a couple things for the new robot, and save it into a commit. Now, lets say you make a change in code A. You change the definition of a function and rename a couple variables.

Now, Git will let you see what branches are caught up with each other, and you can sync changes between them.

Making a branch

To make a branch, click on the little branch button at the bottom of the screen.

Now click the New Branch button, and name it your choice. Now, any new commits will be saved to that branch!

A good practice with branches is to have your master branch always working and without errors. If you are doing major construction or changes, pull it off to a different branch, and when you are done merge back into the master.

Publishing to GitHub

To upload to GitHub, open GitHub Desktop. Click File->Add Local Repository and browse to your project folder. Then click Add Repository. If you click on the History tab, you should see your first commit.

Now click Publish Repository and follow the steps. Your repository is now connected to GitHub! Now, whenever you commit code, you can click the Push button in the PROS Editor to upload your commit to GitHub.

You can now go on github.com and find your repository.

Comment

Leave us a comment or question!

Shopping Basket