Overview
Git basics, branching, remotes, PR flow, and CI/CD hooks.
Init & Clone
git init
git clone https://github.com/user/repo.gitUsage
git init starts a new repo in the current folder. git clone copies a remote repository to your machine.
Stage & Commit
git add .
git commit -m "feat: add learning hub"Usage
git add moves changes to the staging area. git commit creates a snapshot with a message.
Branching & Merging
git branch -M main
git checkout -b feature/x
git merge feature/xUsage
branch creates/renames branches. checkout -b creates and switches. merge integrates history from a branch.
Stash / Reset / Revert
git stash && git stash pop
git reset --hard HEAD~1
git revert <commit>Usage
stash shelves work without committing. reset --hard discards commits. revert creates an inverse commit safely.
Remotes: fetch/pull/push/rebase/cherry-pick
git remote add origin git@github.com:user/repo.git
git fetch --all
git pull --rebase origin main
git push -u origin main
git cherry-pick <commit>
git tag v1.0.0Usage
remote add links a repo. fetch downloads new refs. pull --rebase updates your branch linearly. push publishes. cherry-pick ports a single commit. tag marks releases.
Workflow: GitFlow & PR
# Example flow
git checkout -b feature/login
git commit -m "feat: login form"
git push -u origin feature/login
# Open PR → Review → Merge
git checkout main && git pull && git branch -d feature/loginCI/CD Integration
# GitHub Action example
name: ci
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- run: npm ci && npm testProject: Repo → Feature → PR → Merge
Create a repo, push initial code, develop on a feature branch, open a PR, get review, merge, and tag a release.