Learn / Lessons · GitHub

GitHub basics

Ever lost a good version of your work? Git and GitHub fix that. Git is a tool on your computer that records the history of your files.

Chapters

  1. 0:00Introduction
  2. 0:05Two names: Git and GitHub
  3. 0:16The folder: A repository
  4. 0:28Get a copy: Clone it down
  5. 0:37The daily loop: Change, then save
  6. 0:47Try it: Your first commit
  7. 0:55Share it: Push and pull
  8. 1:04Good habits: Write for later
  9. 1:14Stay safe: Keep secrets out
  10. 1:28From scratch: Start a new one
  11. 1:38Look back: See the history
  12. 1:47Wrap up
Read the transcript

Introduction

Ever lost a good version of your work? Git and GitHub fix that.

Two names: Git and GitHub

Git is a tool on your computer that records the history of your files. GitHub is a website that hosts that history, so you can back it up and work with others.

The folder: A repository

A project lives in a repository, or repo for short. It holds your files, every saved version of them, and usually a read me file that explains the project.

Get a copy: Clone it down

To get a copy onto your machine, clone it. Copy the address from the green Code button on GitHub, then move into the new folder.

git clone https://github.com/you/project.git
cd project

The daily loop: Change, then save

Everyday work is a short loop. Edit your files. Add the changes you want to keep. Commit them, with a message saying what changed.

Try it: Your first commit

Git status shows what has changed. Git add picks a file. Git commit saves the snapshot with your message.

git status
git add README.md
git commit -m "Explain how to install"

Share it: Push and pull

A commit stays on your computer until you share it. Git push sends your commits to GitHub. Git pull brings down what others have added.

Good habits: Write for later

A few habits pay off quickly. Commit small, related changes together. Write messages that say why. And pull before you start new work.

Stay safe: Keep secrets out

Never commit passwords or keys. List private files in a file called git ignore. Check whether a repository is public or private. If a key does get pushed, revoke it. Deleting the line is not enough.

From scratch: Start a new one

Already have a folder of work? Make an empty repository on GitHub. Turn your folder into a Git repository, then point it at GitHub and push.

git init -b main
git add . && git commit -m "First version"
git remote add origin \
  https://github.com/you/project.git
git push -u origin main

Look back: See the history

Your history is easy to read. Git log lists the commits, newest first. Git diff shows what you've changed since the last one.

git log --oneline
git diff

Wrap up

That's the core: clone, edit, add, commit, push.

Sources

More lessons