A story you have already lived
Four students, one mini project, one deadline.
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:
- 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.
- 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.
- 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
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.
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:
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
.exefiles
make the repository huge, because every version is stored whole.
- Git does not merge Word documents or
.psdfiles 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
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.