§Setup & identity
Configure your identity globally. This metadata is attached to all your commits.
# Configure username and email
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
# Check your configuration
git config --list§Daily development cycle
Follow this lifecycle for day-to-day coding:
- 01Switch branch
- 02Write code
- 03Stage changes
- 04Commit
- 05Push to GitHub
Step 1: create a feature branch
Always isolate your changes on a new branch. Avoid committing directly to main.
git switch -c feature/new-cool-featureStep 2: stage & commit changes
Stage files when they reach a logical checkpoint and commit them with a descriptive message.
# Stage specific files
git add path/to/file.js
# Stage all changes
git add .
# Save staged changes to history
git commit -m "feat: implement user registration form"Step 3: push and pull
Keep your local repository in sync with GitHub.
# Push your branch for the first time (sets tracking)
git push -u origin feature/new-cool-feature
# Push subsequent changes
git push
# Pull the latest changes from the remote main branch
git pull origin main§Merging vs. rebasing
When integrating changes from main into your feature branch:
- ●Merge (
git merge main) — use when integrating finished features. Preserves detailed history; adds a merge commit. - ●Rebase (
git rebase main) — use when syncing your local branch with the latest main. Linearizes history; rewrites commit hashes.
§Undoing mistakes
- ●Discard local changes in a file —
git restore <file>— reverts the file to its last committed state. - ●Unstage a staged file —
git restore --staged <file>— removes the file from staging, keeps your edits. - ●Undo last commit, keep changes —
git reset --soft HEAD~1— pulls the changes back into the staging area. - ●Undo last commit, delete changes —
git reset --hard HEAD~1— destroys all changes since the last commit. - ●Revert a pushed commit safely —
git revert <commit-hash>— creates a new commit that undoes the specified commit.
§Stashing & saving work
Use stash to temporarily shelve your current changes if you need to switch branches quickly without committing incomplete work.
# Save uncommitted changes
git stash -m "wip: auth implementation"
# List saved stashes
git stash list
# Restore your latest stash and delete it from the stash list
git stash pop
# Restore a stash but keep it in the list
git stash apply stash@{0}§Resolving merge conflicts
Conflicts occur when Git cannot auto-merge changes — for example, the same line edited on two different branches.
- 01Locate conflicts — run
git statusto see conflicting files. - 02Edit files — look for conflict markers in your code.
- 03Resolve & commit — choose which code to keep, delete the markers (
<<<<<<<,=======,>>>>>>>), then stage and commit.
<<<<<<< HEAD
const URL = "https://api.production.com";
=======
const URL = "https://api.staging.com";
>>>>>>> feature/new-cool-featuregit add <resolved-file>
git commit -m "chore: resolve merge conflict"§Fast commands reference
- ●Initialize repo —
git init - ●Clone repo —
git clone <url> - ●Check status —
git status - ●View differences —
git diff - ●View commit history —
git log --oneline --graph - ●List branches —
git branch - ●Delete branch —
git branch -d <branch-name> - ●Create tag —
git tag -a v1.0.0 -m "Release v1.0.0" - ●Push tags —
git push origin --tags
Shipped it but want a second pair of eyes on your copy, DNS, or email deliverability? bitroot.club does a $0 launch review for anyone who followed this guide. →