Installing Git

Git is the foundation for all types of version control at MIG. It's important to have all your programs and code backed up to our remote repository at all times. This page will show you how to set up.

What is Git?

Git is a software that allows developers to keep track of their version history for their code. Whether it's modifying a line in your main.cpp or a line in your developer.py each change is tracked and stored somewhere in history so that you can go back to it.

Modern Examples

Let's say that you're a working in a project with 3 other people. Each of you guys are working on an item and someone saves their code for the day. Suddenly, all the computers are stolen (for some reason). Your code is completely lost without git and storing it somewhere safe.

Git saves time, effort, and a lot of headache when managing in teams. That's why MIG and companies alike use it so much and is an absolute necessity if you want to get a SWE or Quant job.

Okay so what?

Git is used in just about every project: including open source. In fact Blankly heavily uses git to manage their open source package. Every open source package that you see on Github uses Git as their base. It is now a requirement for all SWE jobs. So definitely be well-versed in how to use Git.

Installation

To install git, first download Git for your specific operating system:

Make sure you add Git to your PATH, otherwise doing anything related to Git will be extremely difficult. This should be a part of the Git installation process (via the GUI)

Installing on Apple

There are two ways to install on Apple, you can either install with the link above. Or you can also go into your terminal and run

$ xcode-select --install

This will install all command line tools that are related to XCode and more.

Installing on Windows and General Notes

Ensure that you install items to the path. In addition, feel free to install any of the supplementary tools that the Git GUI recommends.

Using SourceTree

SourceTree is a GUI based framework that allows you to quickly do Git visually instead of via the command line. It is an easy way to manage git history and offers easy use of various commands such as push, commit and more.

Check it out here.

Using Visual Studio Code Git

Git tooling is built into Visual Studio Code IDE (The default code IDE that we use for MIG). We highly highly recommend using this as this greatly simplifies the need for anything Git related and reduces errors.

Basic Commands

All commands are run in the terminal (or command prompt on Windows)

git init

Git init initializes a new repository in the current working directory that you are working in. This sets up all the version control that you need.

git add .

git add is how we tell git which files and file changes to track. Adding the . at the end signifies that we want to add everything and all changes within the current directory to our version control. We can also write a specific filename like below:

$ git add my_awesome_file.py

git commit -m <message>

git commit will take all the current files that are in tracking (or changed) (the files that were just added via git add and "commit" them to history (like writing it down in a ledger or notes). Now we can git revert back to this commit in the future if we ever make a mistake or lose our code. Each commit must have a message of some sort and must have some code that was git add first.

# Step 1: Add Files
$ git add my_awesome_file.py
# Step 2: Commit to version history
$ git commit -m "I want to add my awesome file" 

git status

Git status allows you to see the current "status" of your version control. Are you ahead of your coworkers? Are you behind? Everything is all about making sure we are on the right version (i.e. our versions are synced). Here's some sample output from my local directory.

$ git status

On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   examples/rsi.py

no changes added to commit (use "git add" and/or "git commit -a")

What does this say? This means that my code is fully updated, and there are no changes to my local directory that I might need to commit and track.

This command will become extremely useful for debugging among your project teams.

git checkout

Git checkout allows you to switch between branches. Branches are how we work on specific pieces of code without interfering with other user's codes. It allows us to sort of create our own experiment (contained environment) without affecting the people around each other.

Creating a New Branch

Creating a new branch is easy and straightforward. This will create a branch from the current branch that you are working on.

$ git checkout -b <branch_name>

Switching Branches

This will switch to a branch name that already exists. If it does not exist, it will throw an error.

$ git checkout <branch_name>

Project teams will use this extensively. It is absolutely imperative that you have this down. Check out the additional resources to learn more about how to merge changes.

git push

Pushing is an integral part to any project as this is how we sync with each other's code remotely. You are pushing to a "remote" repository that is found somewhere in the cloud. Running git push will sync your code with the MIG GitLab or a GitHub repository.

Only push code that works, DO NOT push that code that DOES NOT WORk

Additional Resources

There is a lot more to Git that even I don't know. Git is something that will take everyone years to learn but there are a lot of key parts that anyone can learn and that we will use extensively at MIG.

Need some more help check out these resources for Git?

Last updated