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!
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 directoryls
- This shows (lists) the contents of the current directoryls -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 repositorygit add <filename>
- Add a file (or changes to a file)git add .
- Add all filesgit 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.
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 servergit clone <repository url>
- Get an entire project from the server
Review Questions
The following are examples of questions similar to what you can expect to see on the next exam.
- What is git? A version control program.
- What are some examples of repository hosting websites? GitHub, Bitbucket, MS Azure Dev Ops, GitLab.
-
What does
git init
do? Initializes a local repository. -
When do you use
git init
? When you first create a project. -
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. -
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.