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.
Comments (0)
No comments yet. Be the first!
Leave a Comment