πΏ Industry-Standard Git Branching Strategy and Commands

π Welcome to my Hashnode blog! I'm a Web developer with 7 year's of experience and now I am going to change my domain as DevOps Engineer with lots of hands on experience.
One of the most popular and widely adopted strategies in the industry is the Git Feature Branch Workflow (also referred to as GitHub Flow). It provides clarity, reduces merge conflicts, and ensures code is tested and reviewed before going live.
π Core Branches
mainβ Always production-ready code.developβ (Optional in Git Flow) Contains the latest integrated features before theyβre merged to production.feature/*β Each new feature or enhancement lives here until completed.hotfix/*β Urgent fixes that go directly tomain.release/*β Prepares stable versions for deployment.
π οΈ Example Workflow
Create a feature branch from
develop:git checkout develop git checkout -b feature/user-authWork on your feature, commit changes, and push the branch.
Open a Pull Request (PR) on GitHub β reviewers check code quality.
Merge into
develop.When ready for deployment, merge
developβmain.
β Example Scenario
Letβs say your team is building an E-commerce App:
Create a
feature/cart-checkoutbranch.Test it, then merge into
develop.After QA approval, merge
developintomainfor production.If a critical bug is found in production (e.g., payment not processing), create
hotfix/payment-bugfrommain, fix it, and push immediately.
This strategy ensures stable production, organized feature development, and safe rollbacks.
\==> Git Commands Cheat Sheet (with Explanations)
π§ Configuration
# Set your username
git config --global user.name "Your Name"
# Set your email
git config --global user.email "your@email.com"
# Check configuration
git config --list
π‘ Used once per machine to identify your commits.
π Repository Setup
# Initialize a new Git repository
git init
# Clone an existing repository
git clone https://github.com/user/repo.git
π‘ git init for starting projects, git clone for downloading existing repos.
π Basic Snapshotting
# Check status of files
git status
# Stage a file
git add filename.txt
# Stage all files
git add .
# Commit changes with a message
git commit -m "Added login feature"
# Commit with detailed description
git commit
π‘ git add stages changes; git commit saves them in history.
π Inspect & Review
# Show commit history
git log
# One-line history
git log --oneline
# View file changes
git diff
# View changes in staged files
git diff --staged
π‘ Helps review before pushing or merging.
πΏ Branching & Merging
# List branches
git branch
# Create new branch
git branch feature/login
# Switch to branch
git checkout feature/login
# Create & switch in one step
git checkout -b feature/login
# Merge branch into current branch
git merge feature/login
# Delete branch
git branch -d feature/login
π‘ Branching is essential for features, bug fixes, and experiments.
π Working with Remotes
# Add remote repo
git remote add origin https://github.com/user/repo.git
# Show remote repos
git remote -v
# Push to remote
git push origin main
# Push and set upstream
git push -u origin main
# Pull latest changes
git pull origin main
# Fetch remote changes without merging
git fetch
π‘ git push uploads your code, git pull downloads & merges.
π Undoing Changes
# Unstage a file (keep changes)
git reset filename.txt
# Undo last commit but keep changes
git reset --soft HEAD~1
# Undo last commit & remove changes
git reset --hard HEAD~1
# Checkout file from last commit
git checkout -- filename.txt
π‘ Useful for fixing mistakes safely.
π·οΈ Tags (Releases)
# List tags
git tag
# Create tag
git tag v1.0.0
# Push tags to remote
git push origin v1.0.0
π‘ Tags mark specific commits (e.g., releases).
π§βπ€βπ§ Collaboration (GitHub Flow)
# Create a new branch
git checkout -b feature/cart
# Push feature branch
git push origin feature/cart
# Fetch and merge PR updates
git pull origin feature/cart
π‘ Always work in feature branches, then create Pull Requests (PR).
π Stashing (Work in Progress)
# Stash changes
git stash
# List stashes
git stash list
# Apply last stash
git stash apply
# Drop stash
git stash drop
π‘ Stashing is great when you need to switch branches but arenβt ready to commit.
ποΈ Advanced
# Rebase (replay commits on top of another branch)
git rebase main
# Squash commits interactively
git rebase -i HEAD~3
# Show commit graph
git log --oneline --graph --all
π‘ Re-basing makes history cleaner, squashing combines commits.
π Industry Pro Tips
Always pull before pushing to avoid conflicts.
Use meaningful commit messages (
fix:,feat:,docs:convention).Protect
mainbranch with branch protection rules on GitHub.Prefer feature branching + PR instead of committing directly to
main.#github#Branches



