Commit
A save point with your name on it.
git commit -m "type: message"
Git and GitHub.
git init
git add .
git commit -m "chore: first commit"
git push
Outcomes
A save point with your name on it.
git commit -m "type: message"
Your work on GitHub.
git push
A change ready for review.
git push -u fork my-branch
Format
Type the short commands.
Your fork is disposable.
Stuck for 60 seconds? Ask.
Never paste a command you do not understand.
Plan
Problem
Which one is current?
Commits
Sami · 09:14
Priya · 09:48
Arjun · 10:02
Sami · 10:19
HEADHEAD points to the latest commit.
Git and GitHub
Tracks history. Works offline.
Hosts repositories. Adds pull requests, reviews, and issues.
The three places
Git sees changes here.
You choose what goes in.
Stored in .git.
git status shows where each change is.
The loop
Commit
a1b2c3d feat(people): add sami profile
9f8e7d6 docs: add team wall page
2c4b1a0 chore: start project
The hash identifies the commit. The parent links it to history.
Commit messages
feat(people): add sami profile
fix(nav): correct broken link
docs: update setup guide
chore: initialize repository
Imperative, lowercase, no period.
New feature.
Bug fix.
Documentation.
Maintenance.
Install
winget install --id Git.Git -e --source winget
xcode-select --install
sudo apt install git
git --version
Or download from git-scm.com/downloads.
Configure
git config --global user.name "Sami"
git config --global user.email "me@sam1.space"
git config --global init.defaultBranch main
git config --global --list
repo.Use your own name and GitHub email.
Create a repo, make two commits, read the log.
git initgit logLab 01 · commands
mkdir git-lab
cd git-lab
git init
# create README.md with one line
git status
git add README.md
git commit -m "chore: initialize git lab"
.git existsuntracked becomes stagedgit status is safeREADME.md with one line: # My Git Lab
Windows PowerShell: Set-Content README.md "# My Git Lab"
Lab 01 · checkpoint
# edit README.md, add one line
git diff
git add README.md
git commit -m "docs: add first note"
git log --oneline
git status
nothing to commit, working tree cleangit status.
Remotes
Pull from here.
Livewires-Digital-Solutions/gitting-started
Push here.
github.com/<you>/gitting-started
List every remote.
git remote -v
Vocabulary
Project plus history.
the thingYour copy on GitHub.
GitHubYour copy on the laptop.
git cloneA parallel line of work.
git checkout -bFork the repo, add your profile, open a PR.
originfork remoteLab 02 · setup
# fork on GitHub, then clone the original
git clone https://github.com/Livewires-Digital-Solutions/gitting-started.git
cd gitting-started
git remote add fork https://github.com/<your-handle>/gitting-started.git
git remote -v
git checkout -b add-<your-handle>
cp people/_template.md people/<your-handle>.md
origin is LiveWiresfork is your copyadd-<your-handle>people/<your-handle>.md.
Lab 02 · ship
# edit the file first
git add people/<your-handle>.md
git commit -m "feat(people): add <name> profile"
git push -u fork add-<your-handle>
mainPassword prompt? Use your personal access token.
Pull requests
One branch into another. Review, then merge.
Comment on lines and request changes.
Tests run before merge.
A maintainer accepts the branch.
Good PRs
Add your profile. Nothing else.
“feat(people): add Priya profile.”
What changed and why.
Small diffs get reviewed.
Pull
git checkout main
git pull origin main
Fetch downloads. Merge combines.
origin is the LiveWires repo.
I merged a PR and updated LIVE.md.
git checkout main
git pull origin main
git log --oneline -3
cat LIVE.md
Check LIVE.md. If it says “Already up to date”, raise your hand.
Errors
| Message | Meaning | Fix |
|---|---|---|
fatal: not a git repository |
Wrong folder. | pwd, then cd. |
Authentication failed |
GitHub wants a token. | Use a personal access token. |
Updates were rejected |
Someone pushed first. | git pull, then git push. |
src refspec ... does not match any |
Nothing committed, or wrong branch. | git status · git branch |
nothing to commit |
No saved changes. | Save the file, then git status. |
Before asking: git status and git log --oneline -5.
Undo
| Goal | Command | After push? |
|---|---|---|
| Unstage a file | git restore --staged <file> | Yes |
| Discard local edits | git restore <file> | Yes, edit is gone |
| Fix the last message | git commit --amend -m "Message" | No |
| Undo the last commit, keep changes | git reset --soft HEAD~1 | No |
| Undo a pushed commit | git revert <sha> | Yes |
git reflog remembers where you were for about 30 days. Do not run git reset --hard yet.
Safety
Rotate the secret. Deleting it is not enough.
It rewrites history other people have.
Small PRs get reviewed.
A commit is a save point.
It prevents rejected pushes.
First week
git pullgit checkout -b my-changegit status · git diffgit add · git commitgit push · PRgit status and git log --oneline -5.
Recap
End
Reference
git --version
git config --global user.name "Name"
git config --global user.email "email"
git config --global init.defaultBranch main
git status
git diff
git add <file>
git commit -m "type: message"
git log --oneline
git checkout -b my-branch
git checkout main
git push -u fork my-branch
git pull origin main
git status
git diff --staged
git log --oneline -10
git remote -v
git branch -vv
git restore --staged <file>
git restore <file>
git commit --amend
git reset --soft HEAD~1
git revert <sha>
git reflog
# never commit secrets
# don't force-push shared branches
# one branch, one purpose
# commit small, commit often
# pull before you push