Git, GitHub and Source Control

Christian Grewell
applab 2.0
Published in
4 min readApr 10, 2019

What is Source Control?

Source control is a way to control changes to files and directories, so that you can keep a record of changes and recall specific versions of a file in the event you’d like to back up to an earlier time.

You probably perform some version of local source control, that is, you copy files from one place and put them in other (maybe you ‘backup’ your files to a USB drive). This approach is quite common, but also extremely error prone. It is very easy to overwrite a file, or accidentally copy files you never mean to.

In the past, programmers developed local version control systems that were essentially databases that stored numbered versions of files that needed to have tracked changes.

Distributed Version Control

In this course, we’re going to use distributed version control, specifically, we’re using Git + Github.com (an online versioning system and the home to most open-source software projects). Your local computer has git installed, but there’s a challenge if you want to share your files with others. In a distributed source control system, each user has an entire copy of the version database, and essentially synchronizes changes among two or more of those repositories. Think if it like Google Docs with versioning.

Saving Files the Normal Way

credit: Leon Eckert

When saving files the normal way, you often end up with a structure that looks like this:

my-script.js
my-script_backup.js
my-scriptBETTER.js
my-scriptBETTERv2.js
finalscript.js
FINALfinalscript.js
FINALfinalscript_backup.js
FINALfinalscript_final.js
FINALfinalscript_final_v2.js
FINALfinalscript_final_v3.js
FINALfinalscript_final_v4.js
sweetjesusthisisthefinalone.js
sweetjesusthisisthefinaloneone.js
sweetjesusthisisthefinaloneone_2.js\

Benefits of GIT (Source Control)

You’ll avoid the horror show above where you’re struggling with naming versions of files, or accidentally overwriting an important file, and best of all, when working on projects with others, you’ll avoid the problem where everyone is using different code.

By using a versioning system like Git, you only need to work on a single set of files, and then commit (read: save) your changes. Once you do this, Git will automatically version the committed changes, but the filename will stay the same

credit: Leon Eckert

Git is local

Git is a piece of software that runs on our computer. Once you run it one of your directories by typing git init ,you’ll be able to commit any changes you’ve made to files in that directory or any directories beneath it by typing git commit -m "whatdidyouchange?" where whatdidyouchange? should be a useful note to remind yourself (or others) what you changed.

Think of Git as another way to save files, but instead of saving multiple copies of the same file, you’re first creating a repository (by running the git init command, then committing changes as you work (by running the git commit command followed by a -m "whatdidyouchangeandwhy?"

credit: Leon Eckert

Introduction to GitHub

So Git lets you version files on your computer, and see the changes between those versions (among many other features that we didn’t cover). This is useful, but not groundbreaking. It’s when you have more than two people using Git that it becomes very powerful and extremely useful (it’s the backbone modern software collaboration).

Enter GitHub

First of all, GitHub is not GIT. GitHub is a code hosting platform for collaboration and version control, where you create an online Git repository, then push and pull changes from your local computer’s Git repository.

credit: Leon Eckert

Terms You’ll See When Using GitHub

  • Repositories
  • Commits
  • Git (the version control software GitHub is built on)

Repository

A GitHub repository can be used to store a project. It can contain folders and any type of files (not just code! You can store notes, word docs, gibberish, whatever…).

Commits

Changes to files and folders are called commits. Each commit (change) has a description explaining why a change was made.

The syntax is git commit -m "your note here"

Here’s a 15 minute video showing the entire process of creating a local Git repository, an online GitHub.com repository, committing changes made to a file, and ultimately pushing (read: saving) those changes to the GitHub.com repository.

--

--

Christian Grewell
applab 2.0

Hi! My name is Christian Grewell, I grew up in Portland, Oregon playing music, programming video games, building computers and drinking coffee. I live in China.