Git & GitHub Basics
Version control is how every professional tracks, saves and shares code. Learn Git to record your work and GitHub to store it online — an absolute hiring requirement.
What you will learn
- Explain what Git and GitHub are and how they differ
- Track a project with init, add, commit and a clear history
- Push your code to a GitHub repository others can see
The problem Git solves
Have you ever saved files named index-final.html, index-final-2.html, index-REALLY-final.html? That is version control done badly. Git is a tool that records the full history of your project automatically: every saved version (called a commit) is kept, so you can see what changed, when, and roll back to any earlier point if you break something.
Think of Git as save points in a video game. Every commit is a checkpoint. Mess up later? Load an earlier checkpoint. Want to see exactly what you changed between two points? Git shows you, line by line.
Git vs GitHub — not the same thing
| Git | GitHub | |
|---|---|---|
| What it is | A tool installed on your computer | A website that stores Git projects online |
| Where it runs | Offline, on your machine | In the cloud (github.com) |
| Its job | Records the history of your code | Backs it up and lets others see/collaborate |
| Analogy | The camera taking the photos | The online album you upload them to |
Note: You do not need GitHub to use Git — Git works perfectly offline. But pushing to GitHub backs your work up, gives you a shareable link for your CV, and is how teams collaborate. Alternatives like GitLab and Bitbucket do the same job.
Install and identify yourself (one-time setup)
Install Git from git-scm.com (the VS Code installer offers it too). Then, once ever, tell Git your name and email so it can label your commits. Run these in a terminal — they are not HTML, so there is no live preview; the output is shown after each.
git --version
git config --global user.name "Asha Sharma"
git config --global user.email "asha@example.com"Line by line: git --version checks Git is installed and prints its version. The two git config --global lines store your name and email so every commit you ever make is signed with them. --global means “for all my projects”, so you only do this once per computer.
Note: Output: git version 2.43.0 (The two config commands print nothing — silence means success. Your version number may differ.)
Track a project: the four core commands
Imagine you have a folder my-site with an index.html inside. Here is the everyday Git workflow that turns it into a tracked project with its first save point.
git init
git add index.html
git commit -m "Add homepage with heading and intro"
git statusWalking through each command:
git init— start tracking this folder. Git creates a hidden.gitfolder to store the history.git add index.html— stage the file: tell Git “include this in my next save point.” (Usegit add .to stage every changed file at once.)git commit -m "..."— create the save point with a short message describing what changed. This is the commit.git status— ask Git what is going on: which files changed, what is staged, what is committed.
Note: Output: Initialized empty Git repository in my-site/.git/ [main (root-commit) a1b2c3d] Add homepage with heading and intro 1 file changed, 12 insertions(+) On branch main nothing to commit, working tree clean
That last line, “nothing to commit, working tree clean,” is what you want to see — it means every change is safely saved. The terms: stage = pick what goes into the next commit; commit = the saved snapshot; repository (or repo) = the whole tracked project including its history.
Tip: Write commit messages that finish the sentence “This commit will…”. Good: “Add contact form to about page.” Useless: “stuff”, “asdf”, “update”. Future-you (and your teammates) will read these to understand the project’s story.
Ignore files you should not track
Some files do not belong in version control — system junk, secret passwords, huge generated folders. Create a file named .gitignore listing them, and Git pretends they do not exist.
# .gitignore — one pattern per line
.DS_Store
node_modules/
*.log
.envEach line is a pattern Git will skip: .DS_Store is a Mac system file, node_modules/ is a huge folder you can always re-download, *.log matches any log file, and .env holds secret keys you must never publish. Lines starting with # are comments. For a plain HTML site, ignoring .DS_Store alone is often enough.
Watch out: Never commit passwords, API keys or .env files. Once pushed to GitHub they can be seen by others and stay in the history even if you delete them later. Add them to .gitignore before your first push.
Push your project to GitHub
Now put your local repo online. First create an empty repository on github.com (sign up free, click New repository, give it a name like my-site, and do not add a README so it stays empty). GitHub then shows you commands to connect your folder — they look like this:
git remote add origin https://github.com/yourname/my-site.git
git branch -M main
git push -u origin mainStep by step: git remote add origin <url> tells your local Git where the online copy lives, nicknaming it origin. git branch -M main names your main line of work main (the modern default). git push -u origin main uploads your commits to GitHub; the -u links the two so that next time you can just type git push.
Note: Output: Enumerating objects: 3, done. Writing objects: 100% (3/3), 1.20 KiB, done. To https://github.com/yourname/my-site.git * [new branch] main -> main Refresh github.com/yourname/my-site and your files are there for the world to see.
The everyday loop
Once set up, daily work is a short cycle you will repeat thousands of times:
- Edit your files in VS Code.
git add .to stage what changed.git commit -m "Describe the change"to save a checkpoint.git pushto send it up to GitHub.
Tip: Commit small and often — one logical change per commit — rather than one giant commit at the end of the week. Small commits make your history readable and make it easy to undo a single mistake.
Q. What is the difference between Git and GitHub?
✍️ Practice
- Turn your Personal Profile Page folder into a Git repo: run
git init,git add ., andgit commit -m "Initial profile page". Then rungit logto see your commit. - Add a
.gitignorewith.DS_Storein it, change a heading, then make a second commit describing the change. - Create a free GitHub account and a new empty repository (do not add a README).
🏠 Homework
- Push one of your projects to GitHub and paste the repository link into your course notes. This link is the first thing you can show an employer.