Using GitHub to Manage Software

PR0 Challenge 5.4 [30pts]

omnignorant


Professional software developers use GitHub to keep track of their work… and so will you! A GitHub “repository” or repo (pronounced, reap-oh) is like Google Drive for Hackers!

Our GitHub repo can be found here: https://github.com/hackshop/scholar-work-open

There is very little in there right now, just a sketchbook folder with the blink code. However, as you begin to write code, you will be using this folder to save your work.

There are two ways to use GitHub, either through the web browser (like, by clicking the link above) or through the command line in your terminal.

We will be using the terminal window in Ubuntu to use GitHub and the following instructions require you to continue in Ubuntu.


STEP 1: Tell Git Who You Are

First, open the terminal, then enter the following commands:

git config --global user.name "BSF STEM Scholar"
git config --global user.email stemscholar.bsf@gmail.com

These two commands save your username and email to the git program so that it always knows who you are. You shouldn't have to do it ever again (unless you accidentally erase your system).

STEP 2: Move Into the Right Directory

Next we are going to move to the place where we want to store your work. In Ubuntu, there are sill folders like on your PC at home, but here they are called "directories". You save files into directories.

We're going to move into the "home" directory using the following commands:

cd ~
pwd

That's it, nice and simple. The first command is used to "Change Directory" cd and the ~ symbol means "take me home". The second command asks the computer to display the "Present Working Directory" pwd.

Your present working directory should be:

/home/stemscholar/

STEP 3: Cloning a Repo

Great, now we're going to copy our bsfstemscholars repository from GitHub (online) onto our own computers. This is called "cloning" and is super simple, just type:

git clone https://github.com/hackshop/scholar-work-open

Enter the following username and password:

stemscholar-bsf
#@CK5h0P~

BOOM! some stuff should have happened to tell you it all worked. But to make sure and check, let's move around into the new directory:

cd scholar-work-open
pwd

The pwd command should have returned:

/home/stemscholar/scholar-work-open

You can also check to see what's inside this directory using the following command:

ls -l

which means something like "List" the directory contents. The -l means make it "long format" to give you extra details. You can get fancy by listing what's inside directories inside this directory too! Try:

ls -l *
ls -l sketchbook

You should see the "blink" sketch file inside the sketchbook!

STEP 4: Creating Your Own Branch

So the nice thing about GitHub is that we can store our work online without much fuss, but the nicer thing is that we can all share the same repository while also keeping our own separate branches to keep track of who's doing what.

So, we're going to create your own branch of the scholar-work-open repository. Again, this is very easy, just type the commands:

cd ~/scholar-work-open
pwd

Make sure the pwd command returns:

/home/stemscholar/scholar-work-open

Now let's make your personal branch! Just type (replace your-branch-name with the name of your branch... whatever you want it to be, but do not use spaces, use hyphens instead):

git branch your-branch-name

BOOM! you've got a branch. To check and make sure that it's there, just type:

git branch

And it should return:

* master
  your-branch-name

This means that right now, you are in the "master" branch, which is where everyone starts. Let's move into your branch. The command for that is:

git checkout your-branch-name

I know, the checkout thing is a little confusing, but you can think of that like a library. Each branch is like your personal copy of the repository and in order to use it (or any other branch) you have to "checkout" the branch just like a book in the library.

You can confirm this worked by checking which branch you are in again:

git branch

Which should return:

  master
* your-branch-name

STEP 5: Making Arduino Use This Repo

We want to make sure that all of the work you do gets saved into this repo so that we can always keep it up to date. To do this, you will need to change the settings on your Arduino IDE program in Ubuntu.

Open Arduino in the command line;

  • Go to File > Preferences;
  • Change the location of your repository to be:/home/stemscholar/scholar-work-open/sketchbook/

Now we're almost done.

STEP 6: Saving Your Work to GitHub

PHEW, that was a lot of work to setup, but here's where the magic happens. From this moment forwards, anytime you want to save your progress, all you have to do is this.

Open a terminal window and type these commands:

cd ~/scholar-work-open/
git add *
git commit -a -m 'Hackshop Challenge x.x'
git push origin your-branch-name

Yes, that's it. It will automatically update all of the work in scholar-work-open on your computer to GitHub.

Do this every time you shut down for the day and just make sure to replace "Hackshop Challenge x.x" with the actual challenge.