FirstHack Learn
Log in Sign up free
Lessons in this course 0/6 All courses Git and GitHub for Students

First year

Progress0 / 6 lessons
  1. 1. What version control actually solves
  2. 2. init, add, commit: what a commit really is
  3. 3. Branches and merging
  4. 4. Remotes, push, pull and the rejected-push error
  5. 5. Merge conflicts, resolved step by step
  6. 6. Pull requests, .gitignore and a good README

Courses › Git and GitHub for Students

What version control actually solves

The final_final_v2.zip problem, and why every company fixed it the same way.

8 min read · Lesson 1 of 6 · Free

A story you have already lived

Four students, one mini project, one deadline.

Code
project.zip
project_final.zip
project_final_v2.zip
project_final_v2_ravi_edit.zip
project_FINAL_USE_THIS_ONE.zip
project_final_v2_ravi_edit_FIXED.zip

Ravi edits the login page. Sneha edits the same file at the same time. One of them sends their zip on WhatsApp last, and the other person's four hours of work is gone. Nobody knows when it disappeared or which zip had it.

Then the demo breaks. Somebody says "it worked yesterday". Nobody can prove what yesterday looked like.

Git exists because of exactly this.

What Git gives you

Three things:

  1. History. Every saved state is kept forever, with who changed what,

when, and why. You can go back to any of them in one command.

  1. Parallel work. Two people edit the same project at the same time and

Git merges the changes. It only asks for help when both edited the same lines.

  1. A shared copy. One place online is the truth. No more guessing which

zip is newest.

Git and GitHub are not the same thing

  • Git is a program on your computer. It works with no internet.
  • GitHub is a website that stores copies of Git repositories so people

can share them. GitLab and Bitbucket do the same job.

You can use Git alone forever. GitHub is for sharing, and for having your work visible.

Install and set up, once

BASH
git --version

If that prints a version number, Git is installed. If not, install it from git-scm.com (Windows and Mac) or with sudo apt install git on Ubuntu.

Now tell Git who you are. Every commit records this.

BASH
git config --global user.name "Ravi Kumar"
git config --global user.email "ravi@example.com"
git config --global init.defaultBranch main

Check what you set:

BASH
git config --global --list
⚠️

Use the same email address you use on GitHub. If they differ, your commits appear on GitHub as an unknown author and do not show on your profile. Students notice this months later, after fifty commits, and cannot easily fix the old ones.

The three places a file can be

This is the part most tutorials skip, and it is the reason git add confuses everyone at first.

Place Meaning
Working directory your actual files, as you edit them
Staging area changes you have chosen for the next commit
Repository commits that are saved permanently

git add moves a change from the working directory to the staging area. git commit moves everything staged into the repository.

Why two steps? Because you often fix two unrelated things before you think to save. Staging lets you commit them separately, so the history says "fixed login validation" and "updated README" instead of one commit saying "stuff".

What Git is not

Being honest saves you pain later:

  • Git is not a backup service. If your laptop dies and you never pushed,

the work is gone. Push regularly.

  • Git is bad with large binary files. Videos, datasets and .exe files

make the repository huge, because every version is stored whole.

  • Git does not merge Word documents or .psd files usefully. It merges

plain text: code, HTML, CSS, notes in Markdown.

  • Git will not save you from committing your database password. That

mistake is permanent in the history. Lesson 6 covers .gitignore.

The workflow you will use for years

BASH
git status
git add .
git commit -m "Add student login form"
git push

Four commands. You will type them hundreds of times. By the end of this course you will know what each one does, and what to do when it fails.

💡

Run git status before and after every other command for the first two weeks. It tells you which branch you are on, what is staged, what is changed but unstaged, and usually suggests the exact command you need next. It is the most useful command in Git and it can never break anything.

Next: make your first repository and your first commit.