Work Like a Real Developer with the Git CLI
Stop uploading files through the GitHub web UI. Install git, set up your identity, and learn the daily workflow: clone, add, commit, push, pull, branch, and merge.
What you'll learn
- 1Install git and configure user.name / user.email
- 2Clone a remote repository to your laptop
- 3Use the add β commit β push cycle confidently
- 4Create and switch branches with switch / checkout
- 5Merge branches and resolve simple conflicts
1. Why the CLI?
The GitHub web UI is fine for one file, but breaks down quickly when:
- You change ten files at once
- You need to switch between branches
- You collaborate with teammates
- You want to undo a commit cleanly
Every developer eventually uses git from the terminal. Better to learn it now.
2. Install & Configure Git
Install
| OS | How |
|---|---|
| macOS | xcode-select --install (or brew install git) |
| Windows | https://git-scm.com/download/win β install with defaults |
| Linux | sudo apt install git (or your distro equivalent) |
git --version # should print "git version 2.x.x"
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch mainUse the email tied to your GitHub account β it makes commits show up under your profile.
3. Clone a Repository
Clone copies a remote repo to your laptop. Find the green "Code" button on GitHub and copy the HTTPS URL.
git clone https://github.com/your-name/my-homepage.git
cd my-homepage
ls # files appear locally4. The Daily Cycle: add β commit β push
Every change you make follows the same three-step rhythm.
# 1. Edit files in your editor
# 2. See what changed
git status
git diff
# 3. Stage the files you want to record
git add index.html style.css
# or stage everything: git add .
# 4. Commit with a clear message
git commit -m "Style the navbar with flexbox"
# 5. Push to GitHub
git pushWhat each step does
- add: tell git "include these changes in the next snapshot" (staging area)
- commit: save the snapshot with a message (still local)
- push: upload your local commits to GitHub
Pull before push
If teammates pushed changes, run git pull first to merge them, then push your work.
git pull --rebase
git push5. Branches & Merging
Branches let you work on a feature without breaking the main version. You can have several in flight at once.
git switch -c feature/dark-mode # create + switch
# ... edit and commit ...
git switch main # back to main
git merge feature/dark-mode # bring the work in
git branch -d feature/dark-mode # delete the merged branchHandling conflicts
When two branches change the same lines, git asks you to resolve. Open the marked file, choose the right version, then:
git add <resolved-file>
git commit
# (git auto-fills the merge commit message)6. Reading & Undoing History
git log --oneline -10 # last 10 commits
git show HEAD # latest commit details
git diff HEAD~1 HEAD # diff between two commits
# Undo unstaged changes in a file
git restore index.html
# Unstage a file (keep edits)
git restore --staged index.html
# Revert a pushed commit safely
git revert <commit-hash>Avoid git reset --hard unless you really mean to throw away work. Prefer git revert for anything already pushed.
7. .gitignore
Tell git to ignore noise: build outputs, dependency folders, OS files.
# .gitignore
node_modules/
.DS_Store
.env
build/
.vscode/Commit the .gitignore itself so the whole team shares the same rules.
8. Quick Reference
| Action | Command |
|---|---|
| See what changed | git status / git diff |
| Stage | git add <files> |
| Commit | git commit -m "..." |
| Push | git push |
| Pull | git pull --rebase |
| New branch | git switch -c <name> |
| Switch branch | git switch <name> |
| Merge | git merge <branch> |
| History | git log --oneline |
| Undo unstaged edits | git restore <file> |
π Mini Projects
All lecture materials and example code are openly available on GitHub.
View on GitHub β