Skip to content

Latest commit

 

History

History
92 lines (61 loc) · 3.79 KB

File metadata and controls

92 lines (61 loc) · 3.79 KB

Git — What These Commands Actually Do

Git is a system that tracks every change you make to your code over time. Think of it like Google Docs version history — but for code. Every time you save a version, git remembers it. You can go back to any point.

GitHub is where that history gets stored online, so it's backed up and other people can see it. Git is the tool. GitHub is the warehouse.


The 8 commands you'll actually use

git init

Plain English: "Start watching this folder." You run this once, at the very beginning. It turns a regular folder into one git is tracking. Nothing is saved yet — git is just awake now.

git add

Plain English: "Put these files in the box to be shipped." Git doesn't save everything automatically. You pick which changed files to include in the next save.

  • git add . → put ALL changed files in the box
  • git add filename.py → put just that one file in the box

After this: files are "staged" (ready to save) but not saved yet.

git commit

Plain English: "Seal the box and write a label on it." A commit is a saved snapshot. The -m "message" part is the label you write on the box so you remember what's inside.

  • git commit -m "added login page" → seal and label it

After this: the save exists on your computer. It hasn't gone anywhere yet.

git push

Plain English: "Send the box to GitHub's warehouse." This uploads your saved versions to GitHub. Once it's there, it's backed up and Vercel can see it.

  • git push origin main → send everything to the main branch on GitHub

After this: your code is on GitHub. If Vercel is connected, it starts deploying automatically.

git pull

Plain English: "Bring the latest version down from GitHub to your computer." If anything changed on GitHub since you last looked — pull brings those changes to your machine.

After this: your local files match what's on GitHub.

git clone

Plain English: "Download a complete copy of a project from GitHub."

  • git clone https://github.com/username/repo-name → download the whole thing

After this: you have a full working copy of the project on your machine.

git status

Plain English: "Show me what's changed since my last save." Lists: files you changed but haven't boxed yet, files in the box ready to commit, and files git isn't tracking at all. Nothing changes when you run this — it just shows you the current state.

git remote add origin

Plain English: "Tell git where to send the code when you push." Before you can push, git needs to know the GitHub address. You only do this once per project.

  • git remote add origin https://github.com/username/repo-name.git

After this: git knows where "origin" (GitHub) is. Now push will work.


Common confusion points

"I ran git push and got permission denied" Git is using SSH and your computer hasn't done the secret handshake with GitHub yet. Easiest fix: use HTTPS instead. Get the HTTPS URL from GitHub (starts with https://, not git@) and run git remote set-url origin [that URL].

"fatal: remote origin already exists" You already told git where GitHub is. Instead of add, use set-url: git remote set-url origin https://github.com/your/repo.git

"error: failed to push some refs" GitHub has changes your computer doesn't know about. Run git pull origin main first, then push again.


The full flow — start to finish

First time setting up a project on GitHub:

  1. git init — start watching the folder
  2. git add . — box everything up
  3. git commit -m "first version" — seal and label it
  4. git remote add origin [GitHub URL] — tell git where GitHub is
  5. git push -u origin main — send it

Every time after that:

  1. git add . — box your changes
  2. git commit -m "what you changed" — seal it
  3. git push — send it