What is Git — and why does it matter?
Understanding the core idea before touching a command
Imagine working on training notes and saving them as notes.txt, then notes_v2.txt, then notes_FINAL_really_final.txt… Git is a smarter way to track changes so you never need that chaos.
Git is like a time machine for your files. Every time you save a meaningful checkpoint (called a commit), Git remembers exactly what your project looked like at that moment. You can always go back, compare versions, or work on new ideas without breaking what already works.
🗂 Git
A version control system that runs on your own computer. It tracks every change you make to your files over time. On its own, Git only works locally — to share your work or collaborate with others, you need a hosting platform.
☁️ Git hosting platforms
Websites that store your Git project in the cloud so you can back it up, share it, and collaborate with others. Common examples include GitHub, GitLab, and Bitbucket.
Local vs Remote Repository
Your files live in two places — here's how they relate
A repository (or "repo") is just a folder that Git is tracking. The same project exists in two places: on your personal computer, and on a Git hosting platform in the cloud.
- 📄 notes.txt
- 📝 report.docx
- 📊 data.xlsx
- 📜 commit history
- 📄 notes.txt
- 📝 report.docx
- 📊 data.xlsx
- 📁 .git/
Your local repo is like a printed copy on your desk — you can mark it up freely. The remote repo on your hosting platform is like the master copy in a shared filing cabinet. When you're happy with your changes, you send them up (push). To get the latest version someone else added, you bring it down (pull).
🖥 Local Repository
Lives on your machine. You can edit files, test changes, and use Git — all without internet access.
☁️ Remote Repository
Lives on a Git hosting platform (such as GitHub or GitLab). Serves as the shared, backed-up version that teammates (or your future self) can access.
git add & git commit
Preparing and saving a snapshot of your work
For Git to log the changes made to a file in the local repo, two things need to happen: staging (selecting what to include) and committing (saving the snapshot with a message). Only after committing can you send your updated files to the remote repo.
💡 Saved means your changes are recorded in your local repo. Use git push to send them up to your hosting platform.
Think of sending files from the local repo to the remote repo like shipping a package. git add is putting items into the box — you choose exactly what to include. git commit is sealing and labeling the box before it goes into storage. The label (your commit message) describes what's inside.
Stage your changes with git add
Tell Git which changed files you want to include in the next snapshot.
# Stage a specific file
$ git add .
# Stage ALL changed files in the folder
Save a snapshot with git commit
Lock in your staged changes with a short message describing what you did.
[main 3a2f8c1] Add lecture notes from week 3
1 file changed, 8 insertions(+), 1 deletion(-)
git push & git pull
Syncing changes between your computer and GitHub
Once you've committed locally, your changes still only exist on your machine. push sends them to your hosting platform; pull brings the latest changes from your hosting platform down to your machine.
Connect your local machine to your remote repo with git clone
Before you can push or pull, you need a local copy of your remote repository. Run this once to download it and set up the connection automatically.
Cloning into 'git-practice'...
remote: Counting objects: 3, done.
Receiving objects: 100% (3/3), done.
git clone once per project. After that, use git pull to keep your local copy up to date.git clone is used when a remote repository already exists. If you were starting a brand new project locally from scratch, you would use git init instead — but that is outside the scope of this tutorial.Send your commits to your hosting platform with git push
Uploads all your local commits to the remote repository.
# "origin" = your remote, "main" = the branch name
Enumerating objects: 5, done.
To https://github.com/yourname/myproject.git
3a2f8c1..9b4e2d0 main → main
Get the latest changes with git pull
Downloads new commits from your hosting platform and merges them into your local copy.
remote: Enumerating objects: 3, done.
Updating 3a2f8c1..9b4e2d0
Fast-forward
README.md | 4 ++--
git pull at the start of each session. This ensures you're working from the latest version, especially when collaborating.git pull is a command that downloads the latest changes from a remote repository to your local machine. A Pull Request is a separate concept — it's a request on the hosting platform asking teammates to review and approve your changes before they are merged. We cover Pull Requests in Section 7.Fork & Clone
Copying someone else's project to work on it yourself
Sometimes you want to work on a project you don't own — maybe to contribute, or to use it as a starting point. That's where fork and clone come in. They're related but different.
🍴 Fork (hosting platform action)
Creates a copy of someone else's remote repo under your own account. Done on the hosting platform with one click. The copy is fully yours — you can change it freely without affecting the original.
⬇️ Clone (Git command)
Downloads a repository from your hosting platform to your local computer. Used after forking, or any time you want to work on a project locally for the first time.
Fork the repo on your hosting platform
Go to the repository page, click the Fork button. The hosting platform creates a copy under your account.
Clone your fork to your computer
Copy the URL of your forked repo from your hosting platform, then run:
Cloning into 'training-notes'...
remote: Counting objects: 42, done.
Receiving objects: 100% (42/42), done.
This creates a folder training-notes/ on your machine with all the files inside.
Make changes, then push to your fork
Work locally, commit your changes, and push them to your fork on the hosting platform — not the original.
$ git commit -m "Fix typo in README"
$ git push origin main
Branches
Working on a separate draft without touching the main version
When you're collaborating on training content, you don't want everyone editing the same files at the same time. A branch lets you work on your own version of the project — like a separate draft — without affecting what the rest of the team sees.
Think of the main branch as the published, approved version of your training content — the one everyone relies on. A new branch is like opening a fresh draft copy. You can revise it freely, and when it's ready and reviewed, it gets merged back into the published version. Until then, the original is completely untouched.
Create and switch to a new branch
Give your branch a short, descriptive name that reflects what you're working on.
Switched to a new branch 'update-week3-notes'
Work, add, and commit as usual
All your changes stay on this branch. The main branch is unaffected.
$ git commit -m "Update week 3 notes with new examples"
Push your branch to GitHub
Share your draft branch with the team by pushing it to the remote repo.
Branch 'update-week3-notes' set up to track remote branch.
🌿 main branch
The default, approved version of your project. Think of it as the published copy everyone on the team relies on.
🌱 feature branch
Your personal draft. Make all your changes here until they're ready to be reviewed and merged into main.
Pull Requests
Proposing your changes and getting them reviewed before merging
Once your branch is pushed to your hosting platform, you don't merge it into main straight away. Instead, you open a Pull Request (PR) — a formal way of saying "I'd like to merge my draft. Can someone review it first?"
Think of a pull request like submitting a draft to an editor. You've finished your revisions on your own copy and you're now asking a colleague to look it over before it goes into the official, published version. They can leave comments, request changes, or approve it. Only once it's approved does it get merged into the main content.
Open a Pull Request on GitHub
After pushing your branch, go to the repository on GitHub. You'll see a prompt to open a Pull Request. Give it a clear title and description explaining what you changed and why.
Team reviews your changes
Teammates can read through your changes line by line, leave inline comments, and request edits. You can keep pushing new commits to the same branch to address feedback — the PR updates automatically.
$ git add notes.txt
$ git commit -m "Revise week 3 notes based on feedback"
$ git push origin update-week3-notes
Merge into main once approved
When a teammate approves the PR, click Merge Pull Request on GitHub. Your changes become part of the official main branch, visible to the whole team.