Day 0 | Setting Up Git/Github For Your Coding Projects

What is Version Control?

You’re here because you probably recently heard about Version control. Version control is the practice of managing and tracking changes in a coding project. Some version control systems like Git will also deal with reverting and fast-forwarding changes within a project’s history. Ultimately, it helps developers collaborate, stay organized and work efficiently.

Requirements

Before continuing this guide, make sure you’ve installed Git. You can go to https://git-scm.com/ to do so. The site will detect what OS you are running and give you the appropriate download link. Since I’m using a Mac, the rest of the guide will assume that you are as well.

Here’s where to find the download link on the website

Also, you’ll need to make a Github account at http://github.com/ if you haven’t already.

Link Your Project with Github

As an example workspace, I’m going to make a new directory called VersionControlProject in Terminal using mkdir. This is where I’ll store my project files. I’ll then cd into the directory.

mkdir VersionControlProject
cd VersionControlProject

git init

Inside the VersionControlProject directory, we’ll run git init. This command will initialize a Git repository, (repo for short), within the current directory. We’ll link this new local repo to a remote Github repo that we’ll make later.

git init

git remote add origin <server_url>

This command will create a link between the current local Git repo and a remote repo. You’ll refer to that remote repo as the origin and designate it as such by providing a server URL.

Before we run this command, we need to get a server URL by making the remote Github repo that we mentioned earlier. Therefore we’ll do the following:

  • Go to Github and navigate to the Repositories tab.
  • Click the New button, fill out the information and create the new repo.
  • Afterwards, click on the Code dropdown menu and copy the repo’s URL.

For this example, my VersionControlProject is a Unity project, so I’ll set up the remote repo accordingly.

How to set up a remote Github repo and get its server URL

Afterwards, you’ll run the following command:

git remote add origin <server_url>

replacing ‘<server_url>’ with the repo URL that you just copied from Github.

git remote -v

And that’s it! To verify that your repos are linked, you can run the following command:

git remote -v

This should show that your local repo successfully linked with the origin repo. Additionally, it will show you the permission types that you have with the origin. In this case, it should show that you have Fetch and Push permissions.

  • Fetch allows you to retrieve information from a remote repo.
  • Push allows you to to update local repo changes to a remote repo.

Additional Information

There are many other git commands that can help you with your project management and development. You can find them at https://git-scm.com/docs.