-
Notifications
You must be signed in to change notification settings - Fork 0
Git Introduction
Adrian Patterson edited this page Nov 30, 2020
·
1 revision
- 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
-
GitHub is an amazing tool for any sort of programmer, for the following reasons:
- We can collaborate on programming projects efficiently
- Knowing how to navigate GitHub is useful for finding resources to help with projects. For example, check out the following open-source FRC repos
- FRC Team 254
- FRC Team 2470
- WPI Library These could prove to be really useful for a future robot!
- Finally, GitHub is simply the name of the game these days. GitHub is used far and wide by from open source projects to companies
- There are a few things your computer needs first
- You must have GitBash downloaded.
- The username and password for the GitHub account
- Username: 296RoboticsStudent
- Password: Robostudent296
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
- 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
- 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
-
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 Documentscd Desktop/FRC/RobotsAreLit
-
cd ~will take you back to your home directory
-
List
ls- This command simply lists the files in our working directory
- Example:
- Input:
ls
- Output:
'Folder 1' 'Folder 2' 'Documents' 'Desktop'
- Input:
-
Make Directory
mkdir <directory>- This command will make a new directory of the name passed
- Example:
mkdir frcWorkshopls'frcWorkshop'
This section will cover the needed Git commands we need to push your work to the FRC296 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
- Git commands are similar to terminal commands, but they are used for controlling GitHub from the terminal
-
Cloning a repository
git clone <url>- This command copies a repository into your working directory
- E.g. if you changed directory into
Documentsand then cloned a repository, you'd see the remote reository copied into your local directory
-
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
- This command adds all the files in our working directory to the staging area
-
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
-
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
-
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!
- First log in using git bash with the following command:
git config --global user.email "robostudent@loyola.ca" - We clone the existing repository using its url
git clone https://github.com/FRC296/FRC-Workshop-1.git - We add the files we wish to push to the remote repository
git add .- In this case we're adding all
- We save our work using a commit
git commit - We pull from the remote repository
git pull origin master - And finally, we send our work to the remote repository
git push origin master