Loading
The essential git workflow — commit, branch, merge, and push — explained through practical examples.
Imagine writing a 20-page essay and only having Ctrl+Z to undo mistakes. That's coding without git.
Git gives you:
Every professional software project uses git. Learning it now pays dividends forever.
Understanding the "why" helps the commands make sense.
This creates a hidden .git folder that tracks all changes. You only run git init once per project.
Check the status:
You'll see "No commits yet" — that's normal for a fresh repo.
Create a new repository and check its status.
This is the workflow you'll use hundreds of times:
Key concepts:
Think of it like packing a box (staging) and shipping it (committing).
Practice the add → commit → push loop.
Bad commit messages:
Good commit messages follow Conventional Commits:
Format: type(scope): description
| Type | When to use |
| ---------- | ------------------------------------------------- |
| feat | New feature |
| fix | Bug fix |
| docs | Documentation only |
| refactor | Code change that doesn't add features or fix bugs |
| test | Adding or updating tests |
| chore | Tooling, dependencies, config |
Good commit messages make your project history readable.
Branches let you work on features in isolation:
Branch naming conventions:
feature/description — New featuresfix/description — Bug fixeschore/description — Maintenance tasksCreate a branch, make a commit, and merge it back.
Conflicts happen when two branches change the same line. Git marks them like this:
To resolve:
<<<<<<<, =======, and >>>>>>> markersPro tip: VS Code shows "Accept Current", "Accept Incoming", and "Accept Both" buttons above each conflict.
Conflicts are normal. The important thing is knowing how to resolve them.
After the first push with -u, you can just use git push for subsequent pushes.
Creating a Pull Request (PR):
git push -u origin feature/user-profileConnect your local repo to GitHub and push your code.
| Command | What it does |
| --------------------------- | ------------------------------------ |
| git status | Show changed files |
| git log --oneline | Show commit history (compact) |
| git diff | Show unstaged changes |
| git stash | Temporarily save uncommitted changes |
| git stash pop | Restore stashed changes |
| git reset HEAD~1 | Undo the last commit (keep changes) |
| git blame file.ts | See who changed each line |
| git log --oneline --graph | Visual branch history |
Bookmark this cheat sheet. You'll use these commands daily.
What's next? Learn How to Debug Like a Pro to systematically find and fix bugs in your code.
mkdir my-project
cd my-project
git initgit status"fix stuff"
"update"
"asdfasdf"
"changes"feat(auth): add login form with email validation
fix(api): handle null response from user endpoint
docs(readme): add setup instructions for new developers
refactor(db): extract query builder into separate module<<<<<<< HEAD
const color = "blue";
=======
const color = "red";
>>>>>>> feature/theme# 1. See what changed
git status
# 2. Stage the files you want to commit
git add src/components/Button.tsx
# 3. Commit with a descriptive message
git commit -m "feat(ui): add primary button component"
# 4. Push to the remote repository
git push origin main# Create and switch to a new branch
git checkout -b feature/user-profile
# Do your work...
git add .
git commit -m "feat(profile): add user avatar upload"
# Switch back to main
git checkout main
# Merge your feature
git merge feature/user-profilegit add src/theme.ts
git commit -m "fix: resolve color conflict, keep theme value"# Add a remote repository
git remote add origin git@github.com:your-username/my-project.git
# Push your main branch
git push -u origin main