Contact, if you are interested in this website / domain name / Sponsorship / Advertisement / Partnership
Developer · 9 min read · Updated 2026-10-16

Git & GitHub Basics: The Commands That Matter

A practical introduction to Git and GitHub: commits, branches, merging, remotes, pull requests and the ten commands that cover daily work.

Video: Git and GitHub for Beginners — Crash Course (freeCodeCamp.org). Embedded from YouTube in privacy-enhanced mode; all rights belong to the creator.

Git is a distributed version-control system created by Linus Torvalds in 2005 to manage Linux kernel development. It records snapshots of your project so you can see what changed, when and why, undo mistakes, and work in parallel with others without overwriting each other's work. GitHub is a hosting service built around Git that adds collaboration: pull requests, code review, issues, Actions for CI/CD, and free static hosting with GitHub Pages.

Core concepts in plain English

  • Repository — a project folder plus its full history (stored in a hidden .git directory).
  • Commit — a saved snapshot with a message, author and timestamp. Each commit has a unique SHA-1 (or SHA-256) hash ID.
  • Staging area — the waiting room where you choose exactly which changes go into the next commit.
  • Branch — a movable pointer to a line of commits, letting you develop a feature in isolation.
  • Remote — a copy of the repository elsewhere, typically on GitHub, named origin.

The ten commands you'll use daily

git clone <url>            # copy a remote repo to your machine
git status                  # what's changed and what's staged
git add <file>   / git add -p  # stage changes (-p = choose hunks)
git commit -m "message"     # record a snapshot
git log --oneline --graph   # compact history
git switch -c feature-x     # create and move to a new branch
git pull                    # fetch + merge remote changes
git push -u origin feature-x # publish your branch
git diff                    # unstaged changes
git restore <file>          # discard local changes to a file

A healthy workflow

  1. Pull the latest main.
  2. Create a short-lived branch for one change.
  3. Commit small, logical steps with messages that explain why.
  4. Push and open a pull request; let CI run tests.
  5. Request review, address feedback, then merge (squash merges keep history tidy).
  6. Delete the branch.

Writing good commit messages

Use the imperative mood (“Add password strength meter”, not “Added…”), keep the subject under about 50 characters, and use the body to explain context. Future you — and anyone running git blame — will be grateful.

Undoing things safely

SituationCommand
Fix the last commit messagegit commit --amend
Unstage a filegit restore --staged file
Undo a pushed commitgit revert <sha> (creates an inverse commit)
Recover “lost” workgit reflog

Avoid git push --force on shared branches; if you must, use --force-with-lease, which refuses to overwrite commits you haven't seen.

Never commit secrets

API keys pushed to a public repository are typically found by automated scanners within minutes. Add .env to .gitignore, use your platform's secret store, and if a secret leaks, rotate it immediately — deleting the commit isn't enough because history and forks persist.

Try the tools

Found an error or want a topic covered? Tell us — we review every message.
Get a free tech stack audit