Skip to content

Git Introduction

Adrian Patterson edited this page Nov 30, 2020 · 1 revision

What is GitHub?

  • GitHub is a form of version control. Version control is used we have multiple people working on the same programming project, and we want to make sure the work done is synchronized.
    • Think of GitHub as the Google Docs for coding

Why Learn GitHub?

  • GitHub is an amazing tool for any sort of programmer, for the following reasons:

    1. We can collaborate on programming projects efficiently
    2. Knowing how to navigate GitHub is useful for finding resources to help with projects. For example, check out the following open-source FRC repos
    3. Finally, GitHub is simply the name of the game these days. GitHub is used far and wide by from open source projects to companies

Dependencies

  • There are a few things your computer needs first
    1. You must have GitBash downloaded.
    2. The username and password for the GitHub account
      • Username: 296RoboticsStudent
      • Password: Robostudent296

Terminal Commands

In this section, we'll go over the most basic and essential terminal commands needed for Git. Knowing these commands are very useful in general

What is a terminal?

  • A terminal (AKA console or command line) is a way of communicating with the computer. Communication through the terminal is done using commands, which are usually short abbreviations for actions you want to do
    • A terminal is a computer without its Graphical User Interface (GUI)
    • Some computers don't even have GUIs, and only have a terminal!
      • E.g. RaspberryPis

Who would want to use a computer without a GUI?

  • It sounds a bit silly right? Using a dull-looking terminal over a pretty graphical interface
    • We use terminals because they allow us to directly manipulate and talk to the Operating System (like Windows or Mac).
    • Commands in the terminal can be very powerful for controlling a computer
      • Think of commands as the tools we use to navigate the terminal

The Commands

  1. Change directory

    cd

    • This command allows us to change our working directory, or the directory our terminal is set to
    • Takes in a path as an argument.
      • I.e. the path we want to set our working directory to
    • Examples:
      • cd Documents
      • cd Desktop/FRC/RobotsAreLit
    • cd ~ will take you back to your home directory

  1. List

    ls

    • This command simply lists the files in our working directory
    • Example:
      • Input:
        • ls
      • Output:
        • 'Folder 1' 'Folder 2' 'Documents' 'Desktop'

  1. Make Directory

    mkdir <directory>

    • This command will make a new directory of the name passed
    • Example: mkdir frcWorkshop ls 'frcWorkshop'

Git Commands

This section will cover the needed Git commands we need to push your work to the FRC296 repository.

What is a GitHub Repository?

  • A repository is just a name for a place where we store our code for a project, product, etc.
    • E.g. our repository for Workshop 1 is where all of the workshop material is hosted

What is a Git Command?

  • Git commands are similar to terminal commands, but they are used for controlling GitHub from the terminal

The Commands

  1. Cloning a repository

    git clone <url>

    • This command copies a repository into your working directory
    • E.g. if you changed directory into Documents and then cloned a repository, you'd see the remote reository copied into your local directory

  1. Add changes to the working directory

    git add .

    • This command adds all the files in our working directory to the staging area
      • In other words, we're just telling git what files we want to add to our remote project
    • If you only want to add one file at a time, you'd say git add file.txt

  1. Commit your changes

    git commit

    • This command saves or commits our added files to our local working directory
    • To add a message with your commit, you can say git commit -m "This is my commit message!"
      • and you will see it added on GitHub

  1. Pulling from the remote repository

    git pull origin master

    • Here we are pulling from the origin, or adding the changes we don't have locally
    • We need to do this to make sure our local repository is in the same state as the remote repository

  1. Pushing our changes

    git push origin master

    • Here we are pushing or "sending" the work in our local directory to its remote origin, the master branch
    • That's it!

Recap -- The Final Push

  1. First log in using git bash with the following command:

    git config --global user.email "robostudent@loyola.ca"

  2. We clone the existing repository using its url

    git clone https://github.com/FRC296/FRC-Workshop-1.git

  3. We add the files we wish to push to the remote repository

    git add .

    • In this case we're adding all
  4. We save our work using a commit

    git commit

  5. We pull from the remote repository

    git pull origin master

  6. And finally, we send our work to the remote repository

    git push origin master