Professional WorkflowExtra· 55 min read

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

GitGitHub
What it isA tool installed on your computerA website that stores Git projects online
Where it runsOffline, on your machineIn the cloud (github.com)
Its jobRecords the history of your codeBacks it up and lets others see/collaborate
AnalogyThe camera taking the photosThe 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.

Terminal: confirm Git works and set your identity
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.

Terminal: from a fresh folder to your first commit
git init
git add index.html
git commit -m "Add homepage with heading and intro"
git status

Walking through each command:

  1. git init — start tracking this folder. Git creates a hidden .git folder to store the history.
  2. git add index.htmlstage the file: tell Git “include this in my next save point.” (Use git add . to stage every changed file at once.)
  3. git commit -m "..." — create the save point with a short message describing what changed. This is the commit.
  4. 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 — keep junk and secrets out of Git
# .gitignore — one pattern per line
.DS_Store
node_modules/
*.log
.env

Each 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:

Terminal: connect to GitHub and upload your code
git remote add origin https://github.com/yourname/my-site.git
git branch -M main
git push -u origin main

Step 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:

  1. Edit your files in VS Code.
  2. git add . to stage what changed.
  3. git commit -m "Describe the change" to save a checkpoint.
  4. git push to 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?

Answer: Git is the tool that records your project’s history locally. GitHub is an online service where you store, back up and share Git repositories. You can use Git without GitHub, but not the other way around.

✍️ Practice

  1. Turn your Personal Profile Page folder into a Git repo: run git init, git add ., and git commit -m "Initial profile page". Then run git log to see your commit.
  2. Add a .gitignore with .DS_Store in it, change a heading, then make a second commit describing the change.
  3. Create a free GitHub account and a new empty repository (do not add a README).

🏠 Homework

  1. 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.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →