Git महारत जूनियर को वरिष्ठ डेवलपर्स से अलग करती है। बुनियादी ऐड/कमिट/पुश से परे, उन्नत Git सुविधाएँ – इंटरैक्टिव रिबेस, चेरी-पिक, बाइसेक्ट, वर्कट्रीज़ और हुक – नाटकीय रूप से आपके वर्कफ़्लो और डिबगिंग क्षमताओं में सुधार करती हैं। यह मार्गदर्शिका उन उन्नत Git सुविधाओं को शामिल करती है जिन्हें प्रत्येक डेवलपर को 2026 में जानना चाहिए।
📋 Table of Contents
- इंटरएक्टिव रिबेस – इतिहास को फिर से लिखें
- गिट चेरी-पिक – विशिष्ट प्रतिबद्धताएं लागू करें
- गिट बिसेक्ट – बग-इंट्रोड्यूसिंग कमिट ढूंढें
- गिट वर्कट्री – एकाधिक कार्यशील निर्देशिकाएँ
- गिट रीफ्लॉग – हटाए गए कमिट पुनर्प्राप्त करें
- गिट हुक – स्वचालित वर्कफ़्लो
- गिट स्टैश उन्नत उपयोग
- उपयोगी उन्नत कमांड
- गिट कॉन्फ़िगरेशन युक्तियाँ
इंटरएक्टिव रिबेस – इतिहास को फिर से लिखें
# Squash last 5 commits into one
git rebase -i HEAD~5
# Opens editor with:
# pick a1b2c3d feat: add user authentication
# pick b2c3d4e fix: correct email validation
# pick c3d4e5f docs: add API documentation
# pick d4e5f6a test: add auth tests
# pick e5f6a7b chore: update dependencies
# Change to:
# pick a1b2c3d feat: add user authentication
# squash b2c3d4e fix: correct email validation
# squash c3d4e5f docs: add API documentation
# squash d4e5f6a test: add auth tests
# squash e5f6a7b chore: update dependencies
# Result: one clean commit with all changes
# Other rebase commands:
# reword - edit commit message
# edit - pause to amend commit
# drop - delete commit
# fixup - squash but discard commit message
गिट चेरी-पिक – विशिष्ट प्रतिबद्धताएं लागू करें
# Apply a commit from another branch
git cherry-pick a1b2c3d
# Apply a range of commits
git cherry-pick a1b2c3d..e5f6a7b
# Apply but don't commit yet (--no-commit)
git cherry-pick --no-commit a1b2c3d
# Cherry-pick a merge commit
git cherry-pick -m 1 merge_commit_hash
# Common use case: hotfix on main, apply to release branch
git checkout release/1.2
git cherry-pick fix/critical-security-patch
गिट बिसेक्ट – बग-इंट्रोड्यूसिंग कमिट ढूंढें
# Binary search through commits to find bug introduction
git bisect start
git bisect bad HEAD # current commit has the bug
git bisect good v2.1.0 # this version was fine
# Git checks out a middle commit...
# Test if bug exists, then:
git bisect good # no bug → search upper half
# or
git bisect bad # bug exists → search lower half
# After finding the bad commit:
git bisect reset # return to HEAD
# Automate bisect with a test script
git bisect start
git bisect bad HEAD
git bisect good v2.1.0
git bisect run python test_feature.py # exits 0=good, 1=bad
# Git will tell you: "first bad commit is abc123..."
# Then examine: git show abc123
गिट वर्कट्री – एकाधिक कार्यशील निर्देशिकाएँ
# Work on two branches simultaneously without stashing
git worktree add ../myapp-hotfix hotfix/critical-bug
# Now you have:
# ./myapp/ — main working tree (current branch)
# ../myapp-hotfix/ — second working tree (hotfix branch)
# Both can run independently:
cd ../myapp-hotfix && python manage.py runserver 8001 &
cd myapp && python manage.py runserver 8000 &
# List worktrees
git worktree list
# Remove worktree when done
git worktree remove ../myapp-hotfix
गिट रीफ्लॉग – हटाए गए कमिट पुनर्प्राप्त करें
# See every action Git has tracked (even resets and deleted commits)
git reflog
# Output:
# a1b2c3d HEAD@{0}: reset: moving to HEAD~1
# b2c3d4e HEAD@{1}: commit: add important feature <-- this was "deleted"
# c3d4e5f HEAD@{2}: commit: initial setup
# Recover a "deleted" commit
git checkout -b recovery-branch HEAD@{1}
# Or reset to a previous state
git reset --hard HEAD@{1}
# Reflog is your safety net — all recent actions are tracked
# Default retention: 90 days for reachable refs, 30 for unreachable
गिट हुक – स्वचालित वर्कफ़्लो
# Hooks live in .git/hooks/ (not committed to repo by default)
# Use pre-commit package or Husky for team-shared hooks
# Install pre-commit (Python)
pip install pre-commit
# .pre-commit-config.yaml
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.0
hooks:
- id: ruff # linting
- id: ruff-format # formatting
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: check-yaml
- id: check-json
- id: detect-private-key
# Install hooks
pre-commit install
# Run manually
pre-commit run --all-files
गिट स्टैश उन्नत उपयोग
# Stash with a descriptive name
git stash push -m "WIP: user authentication refactor"
# Stash specific files only
git stash push -m "database changes" -- src/db/models.py src/db/migrations/
# List stashes
git stash list
# stash@{0}: WIP: user authentication refactor
# stash@{1}: database changes
# Apply specific stash (doesn't remove it)
git stash apply stash@{1}
# Pop specific stash (applies and removes)
git stash pop stash@{0}
# Show stash diff
git stash show -p stash@{0}
# Apply stash to different branch
git checkout feature-branch
git stash apply stash@{2}
उपयोगी उन्नत कमांड
# git log — powerful filtering
git log --oneline --graph --all # visual branch history
git log --author="Alice" --since="1 week ago"
git log -S "functionName" # find when a string was added/removed
git log -p -- path/to/file # show diffs for a specific file
# git blame — who wrote each line
git blame src/auth.py
git blame -L 100,150 src/auth.py # specific line range
# git diff — compare anything
git diff HEAD~3 HEAD -- file.py # changes in file over last 3 commits
git diff branch1...branch2 # changes in branch2 since branching from branch1
# git show — inspect a commit
git show a1b2c3d
git show a1b2c3d:src/auth.py # show file at that commit
# git grep — search across commits
git grep "TODO" HEAD -- "*.py"
git grep -n "functionName" # with line numbers
# git add -p — stage hunks interactively
git add -p src/models.py # choose which changes to stage
# Clean untracked files
git clean -n # dry run
git clean -fd # remove untracked files and directories
# git shortlog — contributor summary
git shortlog -sn --no-merges | head -10
गिट कॉन्फ़िगरेशन युक्तियाँ
# Useful global aliases
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all --decorate"
git config --global alias.undo "reset HEAD~1 --mixed"
git config --global alias.wip "commit -am 'WIP'"
# Useful defaults
git config --global pull.rebase true # rebase on pull (not merge)
git config --global push.default current # push current branch only
git config --global rerere.enabled true # remember conflict resolutions
git config --global core.autocrlf input # normalize line endings (macOS/Linux)
# Sign commits with GPG
git config --global commit.gpgsign true
git config --global user.signingkey <YOUR_GPG_KEY_ID>
Git में महारत इन सुविधाओं का नियमित रूप से उपयोग करने से आती है, न कि केवल उनके बारे में पढ़ने से। अपने पीआर वर्कफ़्लो में इंटरैक्टिव रिबेस जोड़ें, बग्स को ट्रैक करते समय बाइसेक्ट का उपयोग करें, और स्थिरता के लिए प्री-कमिट हुक सेट करें। रीफ्लॉग आपका सुरक्षा जाल है – Git में लगभग कुछ भी वास्तव में अपरिवर्तनीय नहीं है।
🔗 Share this article
✍️ Leave a Comment