📡 You're offline — showing cached content
New version available!
Quick Access
SQL Beginner Featured

Git Complete Guide: Branching, Merging, Rebasing and Undoing Mistakes

Master Git — daily workflow, branching strategies, merge vs rebase, stash, cherry-pick, undoing commits safely, and Git Flow for teams.

EzyCoders Admin December 13, 2025 12 min read 0 views
Git Complete Guide Branching Merging Rebasing
Share: Twitter LinkedIn WhatsApp

Git Complete Guide

Git is the universal version control system. Every developer must master branching, merging, rebasing, and conflict resolution for daily professional work.

git config --global user.name  "Rahul Sharma"
git config --global user.email "rahul@ezycoders.in"

git init                       # new repo
git clone URL                  # clone existing
git status                     # what changed?
git add .                      # stage all
git commit -m "feat: add login"
git push origin main

Branching and Merging

git checkout -b feature/user-auth  # create and switch
git switch -c feature/user-auth    # modern syntax

git checkout main
git merge feature/user-auth        # merge (preserves history)
git merge --squash feature/auth    # squash all commits into one

git checkout feature/user-auth
git rebase main                    # replay commits on top of main
git rebase --continue              # after resolving conflicts

git branch -d feature/user-auth   # delete local
git push origin --delete feature/user-auth  # delete remote

Useful Commands

git stash                       # save work-in-progress
git stash pop                   # restore
git log --oneline --graph --all # visual history
git blame src/User.php          # who changed each line

git restore src/file.php        # discard unstaged changes
git reset --soft HEAD~1         # undo commit, keep staged
git reset --hard HEAD~1         # undo commit, DISCARD changes
git revert abc1234              # create undo commit (safe for shared)
git cherry-pick abc1234         # apply specific commit

Q: Merge vs Rebase?

Merge creates a merge commit preserving full history. Rebase replays commits on top of target creating linear history — cleaner but rewrites commit hashes. Never rebase shared/public branches. Rebase your local feature branch before merging to keep main history linear.

EzyCoders Admin
Written by
EzyCoders Admin

Team Lead and Full-Stack Developer with experience in PHP, JavaScript, SQL, DSA, and System Design. Passionate about software engineering, scalable web technologies, and helping developers prepare for coding interviews and tech careers through practical tutorials and professional guidance.

Comments (0)

No comments yet. Be the first!

Leave a Comment