Git and GitHub Basics
What Is Git?
In this lesson you will
- Explain what version control is and why it helps
- Tell the difference between Git and GitHub
- Create a repository and check its status
Introduction
Have you ever saved files called essay-final, essay-final-2 and essay-REALLY-final? Version control solves that mess. It records the history of your work so you can go back, compare, and work with other people without overwriting each other.
The simple explanation
Git is a tool that saves snapshots of your project so you can see and restore any earlier version.
Think of a video game with save points. You can try something risky, and if it goes wrong you return to a save point. Each save point in Git is called a commit.
Git and GitHub are different
- Git is the tool on your computer that tracks changes.
- GitHub is a website that stores Git projects online so you can back them up and share them. Other sites such as GitLab do the same job.
You can use Git without GitHub, but GitHub makes teamwork easier.
Quick quiz
What is the difference between Git and GitHub?
Your first repository
A repository (or repo) is a project folder that Git is tracking. After installing Git from git-scm.com, open a terminal and run these commands. The lines starting with # are comments for you to read.
Terminal
# make a folder and move into it
mkdir my-project
cd my-project
# tell Git to start tracking this folder
git init
# ask Git what is going on
git statusgit init creates a hidden folder named .git where Git keeps its history. git status is the command you will use most. It tells you which files are new, changed, or ready to be saved. In a brand new repo it says there is nothing to commit yet.
Tell Git who you are
Git puts your name on every commit. Set it once:
Terminal
git config --global user.name "Your Name"
git config --global user.email "[email protected]"Try it yourself
Install Git, create a folder, run git init and then git status. Look at what Git says. You will make your first commit in the next lesson.
Summary
- Version control records the history of your work so you can go back.
- Git is the tool on your computer; GitHub is a site that hosts Git projects.
git initstarts tracking a folder andgit statusshows what is happening.
Lesson complete
+20 XP
Nice work. Keep going while it is fresh.
Sources and further reading