⧼⧼  Previous Page
⧼  Table of Contents  ⧽
Next Page  ⧽⧽

Introduction to Git Source Control

Computer Programming C++ / Getting Started

Since version control is probably a new topic for you, let's start with the basics. What is version control? For that, lets look at an example. Imagine for a moment that you're working on a thirty page essay. By the time that you're finished, you have six different files: essay.doc, essay2.doc, essay2-finished.doc, essay2-finished-revised.doc, essay2-finished-revised-FINAL.doc, essay2-finished-revised-final-REALLY.doc. Version control programs keep track of the history of a document, so you can avoid situations like this.

Keeping track of the history of a document, becomes extremely important when you're working on a team. Using the example from before, imagine what would happen if another student were to work on one of these files at the same time as you. Best case scenereo, you have to go back and combine the results. Worst case, your work gets overwritten!

There are some applications out there, google docs for example, that will allow multiple users to work on the same document. Git adds more advanced features that we will look at in the future.

We're going to be using Git and Bitbucket for doing all of this. Often people are confused about the difference between Git and Github. This video will explain what they are.

You will need to download Git from git-scm.com, and to create an account at bitbucket.org.

Folder Navigation

Before diving into Git, there are a few commands that you'll need to know. They have to do with navigating your directory structure via the command line. They are:

  • cd <folder> - This sets the current directory
  • ls - This shows (lists) the contents of the current directory
  • ls -a - This will include any hidden folders (show all)

Introduction to Git Bash

It's time to jump in! The following video will get you aquainted with the following commands:

  • git init - Initialize the repository
  • git add <filename> - Add a file (or changes to a file)
  • git add . - Add all files
  • git commit -m "<your comment message>" - Commit (or version) your changes.

Like the previous video states, you will likely run into a common commit mistake. Let's take a look:

For future reference:
Press Escape, then type :q!, and press Enter.

Push, Pull & Clone

Next, let's setup a place for our project to live on the internet.

A git project is usually referred to as a "repository" or just "repo" for short.

Now that our code is up on the internet. We need to learn how to get it back down. There are two commands to do this. The one that you choose depends on whether or not the project is already on the computer.

Let's say I was working at home, I created a new project, then pushed it up to Bitbucket. After that I went to work. Since the project isn't on my work computer, I would need to clone it. Cloning creates a copy on my local computer. After going home for the day, I wanted to work on it again, so I do a pull. Pulling gets the changes that are made on the server. Let's see how these are done:

  • git pull - Gets the changes from the server
  • git clone <repository url> - Get an entire project from the server
I don't ever type out the clone command. There's usually a link on the server that I can copy!

Review Questions

The following are examples of questions similar to what you can expect to see on the next exam.

Hover over a question to show the answer.
  1. What is git? A version control program.
  2. What are some examples of repository hosting websites? GitHub, Bitbucket, MS Azure Dev Ops, GitLab.
  3. What does git init do? Initializes a local repository.
  4. When do you use git init? When you first create a project.
  5. When would you use git clone vs. git pull? You would use pull if the project is already on your computer, otherwise you would clone it.
  6. What git commands are used the most? You should be using add and commit often as you're working
    on a project, therefore they should be used the most.
⧼⧼  Previous Page
⧼  Table of Contents  ⧽
Next Page  ⧽⧽
© Ryan Appel