Git is the most widely used distributed version control system (DVCS) in the world, created by Linus Torvalds in 2005 to manage the Linux kernel source code. This is an exhaustive reference covering every major Git command, workflow, and internal concept â from your first git init to advanced plumbing commands used by Git itself internally. By the end, you will not need any other Git resource.
Information
1. Introduction to Git đ
1.1 What is Version Control?
Version control is a system that records changes to files over time so you can recall specific versions later. Git specifically is a distributed system â every clone is a full backup of the entire project history, not just the latest snapshot.
1.2 Git vs Other VCS
| Feature | Git (Distributed) | SVN / CVS (Centralized) |
|---|---|---|
| Repository copies | Full history on every machine | Only server has full history |
| Offline work | Fully supported | Limited |
| Branching cost | Cheap and instant | Expensive and slow |
| Speed | Very fast (local operations) | Slower (network dependent) |
1.3 Why Git Wins
- đ Tracks every change with full history
- đ Cheap, instant branching and merging
- đ¤ Built for distributed team collaboration
- âĒ Safe reverting and recovery mechanisms
- đ Ecosystem support: GitHub, GitLab, Bitbucket, Azure DevOps
- ⥠Extremely fast due to local operations
2. Installing and Configuring Git âī¸
2.1 Installation
| OS | Command / Method |
|---|---|
| Windows | Download from git-scm.com |
| macOS | brew install git |
| Ubuntu/Debian | sudo apt install git |
| Fedora/RHEL | sudo dnf install git |
| Arch Linux | sudo pacman -S git |
Check Installed Git Version
git --version2.2 Identity Configuration
Set Global Username and Email
git config --global user.name "Your Name"
git config --global user.email "you@example.com"Check Configured Username
git config user.name2.3 Configuration Levels
| Flag | Scope | File Location |
|---|---|---|
| --local | Current repository only (default) | .git/config |
| --global | All repos for current user | ~/.gitconfig |
| --system | All users on the machine | /etc/gitconfig |
2.4 Useful Configuration Settings
Set Default Editor (VS Code)
git config --global core.editor 'code --wait'Set Default Branch Name to 'main'
git config --global init.defaultBranch mainLine Ending Handling (macOS/Linux)
git config --global core.autocrlf inputLine Ending Handling (Windows)
git config --global core.autocrlf trueEnable Colored Output
git config --global color.ui autoSet Default Pull Strategy to Merge
git config --global pull.rebase falseView All Config With File Origins
git config --list --show-originCache Credentials Temporarily
git config --global credential.helper cacheRemove a Config Value
git config --global --unset user.nameTip
3. Getting Help đ
Open Manual Page for a Command
git help commitAlternative Way to View Command Docs
git commit --helpQuick Inline Usage Summary
git commit -h4. Creating and Cloning Repositories đ
4.1 Initializing a New Repository
Initialize a New Git Repository
git initInitialize a Repository in a New Folder
git init my-projectCreate a Bare Repository (No Working Directory)
git init --bareInitializing creates a hidden .git folder that stores all history, references, and configuration for the repository.
4.2 Cloning an Existing Repository
Clone a Remote Repository (HTTPS)
git clone https://github.com/user/repo.gitClone a Remote Repository (SSH)
git clone git@github.com:user/repo.gitClone into a Custom Folder Name
git clone https://github.com/user/repo.git my-folderShallow Clone (Only Latest Commit)
git clone --depth 1 https://github.com/user/repo.gitClone a Specific Branch
git clone --branch develop https://github.com/user/repo.gitClone Including All Submodules
git clone --recurse-submodules https://github.com/user/repo.gitNote
5. Git Internals: How Git Actually Stores Data đ§Ŧ
Understanding Git's internal object model demystifies everything else. Git is fundamentally a content-addressable key-value store.
5.1 The Four Object Types
| Object | Purpose |
|---|---|
| Blob | Stores raw file content (no filename/metadata) |
| Tree | Represents a directory; maps names to blobs/trees |
| Commit | Points to a tree snapshot + parent commit(s) + metadata |
| Tag | A named, often signed, pointer to a commit |
5.2 Plumbing Commands (Low-Level)
Compute SHA-1 Hash of a File's Content
git hash-object filename.txtPretty-Print Any Git Object
git cat-file -p commit-hashShow the Type of a Git Object
git cat-file -t commit-hashResolve HEAD to Its Full Commit Hash
git rev-parse HEADList Contents of a Tree Object
git ls-tree HEADInformation
5.3 The .git Directory Structure
| Path | Purpose |
|---|---|
| .git/HEAD | Points to the current branch reference |
| .git/refs/heads/ | Local branch pointers |
| .git/refs/tags/ | Tag pointers |
| .git/objects/ | Compressed storage for all blobs/trees/commits |
| .git/config | Repository-specific configuration |
| .git/index | The staging area binary file |
6. The Git Workflow: Three Trees đ
| Area | Description |
|---|---|
| Working Directory | Your actual project files on disk |
| Staging Area (Index) | Files marked to be included in the next commit |
| Repository (.git) | Permanent, committed history of your project |
6.1 Checking Status
View Current State of the Working Directory
git statusView Status in Short Format
git status -s6.2 Staging Changes
Stage a Specific File
git add filename.txtStage an Entire Folder
git add folder/Stage All Changes in Current Directory
git add .Stage All Changes Including Deletions (Entire Repo)
git add -AStage Modified/Deleted Files Only (Not New Files)
git add -uInteractively Stage Hunks Within a File
git add -pStage a New File as 'Intent to Add' (Tracks Without Content)
git add -N filename.txt6.3 Committing Changes
Commit Staged Changes with a Message
git commit -m "Add login feature"Stage All Tracked Files and Commit Together
git commit -am "Fix bug in auth module"Open Editor for a Multi-line Commit Message
git commitModify the Last Commit's Message or Content
git commit --amendAdd Staged Changes to Last Commit Without Changing Message
git commit --amend --no-editCreate an Empty Commit
git commit --allow-empty -m 'Trigger CI'Create a GPG-Signed Commit
git commit -S -m 'Signed commit'Warning
6.4 Commit Message Best Practices
- Use imperative mood: "Add feature" not "Added feature"
- Keep the subject line under 50 characters
- Leave a blank line, then add a detailed body if needed
- Reference issue numbers when relevant (e.g., Fixes #42)
7. Viewing History and Differences đ
7.1 Viewing Commit Logs
View Full Commit History
git logView Condensed Commit History
git log --onelineVisualize Full Branch History as a Graph
git log --oneline --graph --all --decorateView Commit History with Diffs for a File
git log -p filename.txtFilter Log by Author
git log --author='Jane'Filter Log by Date
git log --since='2 weeks ago'Search Commit Messages by Keyword
git log --grep='fix'Show File Change Statistics per Commit
git log --statShow Commits in branch2 Not in branch1
git log branch1..branch2Summarize Commit Counts per Author
git shortlog -sn7.2 Viewing Differences
View Unstaged Changes
git diffView Staged Changes (Also: --cached)
git diff --stagedCompare Two Branches
git diff branch1 branch2Compare Current State to 3 Commits Ago
git diff HEAD~3 HEADShow Word-Level Differences Instead of Lines
git diff --word-diffCompare Two Sets of Commits (e.g., Before/After Rebase)
git range-diff main~5..main main~5..origin/main7.3 Inspecting Objects
Show Full Details of a Specific Commit
git show commit-hashShow File Content at a Specific Commit
git show HEAD~2:filename.txtShow Who Last Modified Each Line
git blame filename.txtBlame Only Lines 10 to 20
git blame -L 10,20 filename.txt8. Branching đŋ
Branches let you work on features, fixes, or experiments in isolation without affecting the main codebase. In Git, a branch is simply a lightweight, movable pointer to a commit.
8.1 Managing Branches
List All Local Branches
git branchList All Local and Remote Branches
git branch -aList Remote-Tracking Branches Only
git branch -rCreate a New Branch (Without Switching)
git branch feature-loginDelete a Merged Branch
git branch -d feature-loginForce Delete an Unmerged Branch
git branch -D feature-loginRename a Branch
git branch -m old-name new-nameList Branches Already Merged into Current
git branch --mergedFind Which Branches Contain a Commit
git branch --contains commit-hash8.2 Switching Branches
Switch to an Existing Branch (Legacy)
git checkout feature-loginCreate and Switch to a New Branch (Legacy)
git checkout -b feature-paymentSwitch to an Existing Branch (Modern)
git switch feature-loginCreate and Switch to a New Branch (Modern)
git switch -c feature-paymentSwitch Back to the Previous Branch
git switch -Best Practice
9. Merging and Rebasing đ
9.1 Merging Branches
Merge a Branch into the Current Branch
git merge feature-loginForce a Merge Commit (No Fast-Forward)
git merge --no-ff feature-loginCombine All Branch Commits into One
git merge --squash feature-loginCancel a Merge in Progress
git merge --abort9.2 Handling Merge Conflicts
Conflict Marker Example
<<<<<<< HEAD
Your current changes
=======
Incoming changes
>>>>>>> feature-branch- Open the conflicting file(s) and manually resolve differences
- Remove the conflict markers (<<<<<<<, =======, >>>>>>>)
- Run git add filename to mark it resolved
- Run git commit to complete the merge
List All Files with Unresolved Conflicts
git diff --name-only --diff-filter=UKeep Your Version of a Conflicted File
git checkout --ours filename.txtKeep Their Version of a Conflicted File
git checkout --theirs filename.txtLaunch a Visual Merge Conflict Resolution Tool
git mergetool9.3 Rerere (Reuse Recorded Resolution)
Enable Automatic Conflict Resolution Memory
git config --global rerere.enabled trueTip
9.4 Rebasing
Rebase Current Branch onto Main
git rebase mainInteractive Rebase (Last 3 Commits)
git rebase -i HEAD~3Continue Rebase After Resolving a Conflict
git rebase --continueCancel a Rebase in Progress
git rebase --abortSkip the Current Commit During Rebase
git rebase --skipReplay Commits onto a Different Base
git rebase --onto main feature-old feature-newInteractive Rebase Todo List Example
pick a1b2c3 Add login form
squash d4e5f6 Fix typo in login form
reword g7h8i9 Improve validation logicCaution
9.5 Merge vs Rebase
| Aspect | Merge | Rebase |
|---|---|---|
| History | Preserves branch history | Creates linear history |
| Commit graph | Non-linear, more complex | Clean and simplified |
| Safety on shared branches | Safe | Risky (rewrites history) |
10. Working with Remotes đ
10.1 Managing Remote Repositories
List Remote Repositories with URLs
git remote -vAdd a New Remote
git remote add origin https://github.com/user/repo.gitRename a Remote
git remote rename origin upstreamRemove a Remote
git remote remove originChange a Remote's URL
git remote set-url origin git@github.com:user/repo.gitShow Detailed Info About a Remote
git remote show origin10.2 Fetching and Pulling
Fetch Changes Without Merging
git fetch originFetch from All Configured Remotes
git fetch --allFetch and Remove Stale Remote-Tracking Branches
git fetch --pruneFetch and Merge Changes from Remote
git pull origin mainPull and Rebase Instead of Merge
git pull --rebase origin mainPull Only if a Fast-Forward is Possible
git pull --ff-only10.3 Pushing Changes
Push Commits to Remote Branch
git push origin mainPush and Set Upstream Tracking Branch
git push -u origin feature-loginPush All Local Branches
git push --allPush All Tags
git push --tagsForce Push (Overwrites Remote History)
git push --forceSafer Force Push (Fails if Remote Has New Commits)
git push --force-with-leaseDelete a Remote Branch
git push origin --delete feature-loginDanger
11. Undoing Changes âĒ
11.1 Unstaging and Discarding
Discard Changes in Working Directory
git restore filename.txtUnstage a File (Keep Changes)
git restore --staged filename.txtRestore a File to an Older Version
git restore --source=HEAD~2 filename.txtDiscard Changes (Legacy Syntax)
git checkout -- filename.txt11.2 Resetting Commits
Undo Last Commit, Keep Changes Staged
git reset --soft HEAD~1Undo Last Commit, Keep Changes Unstaged (Default)
git reset --mixed HEAD~1Undo Last Commit and Discard All Changes
git reset --hard HEAD~1Unstage a Specific File
git reset filename.txtWarning
11.3 Reverting Commits
Create a New Commit That Undoes a Previous One
git revert commit-hashRevert a Range of Commits
git revert HEAD~3..HEADRevert Without Auto-Committing
git revert --no-commit commit-hashBest Practice
12. Stashing Changes đĻ
Stashing temporarily shelves uncommitted changes so you can switch context without committing incomplete work.
Stash Current Changes
git stashStash with a Descriptive Message
git stash save "WIP: navbar redesign"Stash Including Untracked Files
git stash -uView All Stashes
git stash listView Full Diff of a Specific Stash
git stash show -p stash@{0}Apply the Most Recent Stash (Keep it in List)
git stash applyApply a Specific Stash by Index
git stash apply stash@{2}Apply and Remove the Most Recent Stash
git stash popDelete a Specific Stash
git stash drop stash@{1}Remove All Stashes
git stash clearCreate a New Branch from a Stash
git stash branch new-branch stash@{0}13. Tagging đˇī¸
Tags mark specific points in history, typically used for releases (e.g., v1.0.0).
Create a Lightweight Tag
git tag v1.0.0Create an Annotated Tag
git tag -a v1.0.0 -m "First stable release"Create a GPG-Signed Tag
git tag -s v1.0.0 -m 'Signed release'List All Tags
git tagList Tags Matching a Pattern
git tag -l 'v1.*'Tag an Older Commit
git tag -a v0.9 commit-hash -m 'Retroactive tag'Push a Specific Tag to Remote
git push origin v1.0.0Push All Tags to Remote
git push origin --tagsDelete a Local Tag
git tag -d v1.0.0Delete a Remote Tag
git push origin --delete tag v1.0.014. Ignoring and Tracking Files đĢ
14.1 .gitignore
Example .gitignore File
# Node modules
node_modules/
# Environment variables
.env
# Build output
dist/
build/
# OS-specific files
.DS_StoreHint
14.2 Managing Already-Tracked Ignored Files
Stop Tracking a File Without Deleting It
git rm --cached filename.txtDebug Why a File is Being Ignored
git check-ignore -v filename.txt14.3 .gitattributes
Example .gitattributes File
*.jpg binary
*.sh text eol=lf
*.md diff=markdownInformation
15. File and Directory Operations đ
Rename/Move a Tracked File
git mv oldname.txt newname.txtDelete a File and Stage the Deletion
git rm filename.txtDelete a Folder Recursively
git rm -r folder/Untrack a File but Keep it Locally
git rm --cached filename.txt16. Searching and Finding đ
Search Tracked Files for a Pattern
git grep 'TODO'Search with Line Numbers
git grep -n 'function login'Find Commits That Added/Removed a String (Pickaxe)
git log -S'functionName'Find Commits Matching a Regex in Diffs
git log -G'regex.*pattern'17. Advanced Commands đ§
17.1 Cherry-Picking
Apply a specific commit from one branch onto another without merging the entire branch.
Apply a Specific Commit to Current Branch
git cherry-pick commit-hashCherry-Pick Multiple Commits
git cherry-pick commitA commitBCherry-Pick Without Auto-Committing
git cherry-pick --no-commit commit-hashAbort a Cherry-Pick in Progress
git cherry-pick --abort17.2 Bisecting (Finding Bugs)
Binary Search to Find a Bug-Introducing Commit
git bisect start
git bisect bad
git bisect good v1.0.0End the Bisect Session and Return to Original Branch
git bisect resetExample
17.3 Reflog (Recovering Lost Work)
View Reference Log of All HEAD Movements
git reflogRecover to a Previous State Using Reflog
git reset --hard HEAD@{2}Success
17.4 Submodules
Add a Submodule
git submodule add https://github.com/user/library.git libs/libraryInitialize and Update Submodules
git submodule update --init --recursiveUpdate Submodules to Latest Remote Commit
git submodule update --remoteRemove a Submodule
git submodule deinit libs/library17.5 Subtree
Add a Repository as a Subtree
git subtree add --prefix=libs/mylib https://github.com/user/mylib.git main --squashPull Updates into a Subtree
git subtree pull --prefix=libs/mylib https://github.com/user/mylib.git main --squash17.6 Worktrees
Create a Separate Working Directory for a Branch
git worktree add ../hotfix-branch hotfixList All Active Worktrees
git worktree listRemove a Worktree
git worktree remove ../hotfix-branchInformation
17.7 Clean
Preview Untracked Files to be Removed (Dry Run)
git clean -nRemove Untracked Files
git clean -fRemove Untracked Files and Directories
git clean -fdRemove Untracked and Ignored Files
git clean -fx17.8 Archive and Patches
Export Repository as a ZIP File
git archive --format=zip HEAD -o project.zipCreate Patch Files for the Last 3 Commits
git format-patch -3Apply a Patch File as a Commit
git am patch-file.patchApply a Raw Diff Without Committing
git apply changes.diff17.9 Notes
Attach a Note to a Commit
git notes add -m 'Reviewed by QA' commit-hashView a Commit's Notes
git notes show commit-hash17.10 Sparse Checkout (Large Monorepos)
Checkout Only Specific Folders from a Large Repo
git sparse-checkout init --cone
git sparse-checkout set frontend/ shared/17.11 Maintenance and Integrity
Clean Up and Optimize the Local Repository
git gcCheck Repository Integrity for Corruption
git fsckRemove Unreachable Objects
git pruneShow Repository Object Count and Disk Usage
git count-objects -vEnable Automatic Background Maintenance
git maintenance start17.12 Filtering Large Files from History
Permanently Remove a File from All History (Modern Tool)
git filter-repo --path secrets.txt --invert-pathsDanger
17.13 Git LFS (Large File Storage)
Enable Git LFS in a Repository
git lfs installTrack Large Binary Files with LFS
git lfs track '*.psd'List Files Tracked by LFS
git lfs ls-files18. Git Hooks đĒ
Hooks are scripts that run automatically at specific points in the Git workflow (e.g., before a commit or push). They live in .git/hooks/.
Example pre-commit Hook
#!/bin/sh
# .git/hooks/pre-commit
npm run lint
if [ $? -ne 0 ]; then
echo "Lint failed. Commit aborted."
exit 1
fi| Hook | Triggered When |
|---|---|
| pre-commit | Before a commit is created |
| commit-msg | After the commit message is written |
| pre-push | Before pushing to a remote |
| post-merge | After a successful merge |
Tip
19. Authentication and Security đ
19.1 SSH Setup
Generate a New SSH Key
ssh-keygen -t ed25519 -C "you@example.com"Copy Your Public Key to Add on GitHub
cat ~/.ssh/id_ed25519.pubTest SSH Connection to GitHub
ssh -T git@github.com19.2 GPG Commit Signing
Set Your GPG Signing Key
git config --global user.signingkey YOUR_KEY_IDSign All Commits Automatically
git config --global commit.gpgsign trueBest Practice
20. Git Aliases âĄ
Create Useful Git Aliases
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.lg "log --oneline --graph --all"
git config --global alias.undo "reset --soft HEAD~1"Tip
21. Common Git Workflows đ§Š
21.1 Feature Branch Workflow
- Create a branch from main: git switch -c feature-x
- Make changes and commit regularly
- Push the branch: git push -u origin feature-x
- Open a Pull Request for review
- Merge into main after approval
21.2 Gitflow Workflow
A structured branching model using dedicated branches: main, develop, feature/*, release/*, and hotfix/*. Best suited for projects with scheduled release cycles.
21.3 Trunk-Based Development
Developers commit small, frequent changes directly to main (or very short-lived branches), relying heavily on feature flags and CI/CD. Preferred by teams practicing continuous deployment.
21.4 Forking Workflow
Common in open-source projects: contributors fork the repository, make changes in their fork, then submit a Pull Request back to the original repository.
22. Troubleshooting Common Issues đ ī¸
| Problem | Solution |
|---|---|
| Detached HEAD state | git switch -c new-branch-name to save your work |
| Committed to wrong branch | git reset --soft HEAD~1 then switch and re-commit |
| Accidentally deleted a branch | git reflog to find the last commit hash, then git branch recovered-branch hash |
| Large file rejected by remote | Use git lfs or remove it with filter-repo |
| Merge conflict overwhelm | Use git mergetool or abort with git merge --abort |
Question
23. Complete Command Cheat Sheet đ
| Category | Key Commands |
|---|---|
| Setup | git init, git clone, git config |
| Staging | git add, git rm, git mv |
| Committing | git commit, git commit --amend |
| Branching | git branch, git switch, git checkout |
| Merging | git merge, git rebase, git cherry-pick |
| Remote | git push, git pull, git fetch, git remote |
| History | git log, git diff, git show, git blame |
| Undo | git reset, git revert, git restore |
| Stashing | git stash |
| Tags | git tag |
| Debugging | git bisect, git reflog, git blame |
| Advanced | git submodule, git worktree, git filter-repo, git lfs |
| Maintenance | git gc, git fsck, git prune |
24. Summary â
Summary
- â Use clear, descriptive, imperative-mood commit messages
- â Commit small, logical changes frequently
- â Pull before you push to avoid conflicts
- â Never force-push to shared branches without --force-with-lease
- â Use .gitignore and .gitattributes to keep repositories clean
- â Enable rerere if you rebase frequently
- â Sign commits/tags with GPG for verified authorship
- â Run git gc periodically on large repositories
Reference
Git is a parallel universe machine for code. Every commit = a save point. Every branch = an alternate timeline. Every merge = controlled chaos đ
1. Install Git
Check installation
Code Snippet
git --version
2. Initial Configuration
Set username
Code Snippet
git config --global user.name "Your Name"
Set email
Code Snippet
git config --global user.email "you@example.com"
View config
Code Snippet
git config --list
3. Create Repository
Initialize Git
Code Snippet
git init
Creates hidden .git folder đ§
4. Git Workflow Basics
Code Snippet
Working Directory â Staging Area â Repository
5. Check Status
Code Snippet
git status
Shows:
- modified files
- staged files
- untracked files
6. Add Files
Add single file
Code Snippet
git add app.js
Add all files
Code Snippet
git add .
7. Commit Changes
Create commit
Code Snippet
git commit -m "Added login feature"
Think of commit messages as breadcrumbs for future-you đĨ
8. View Commit History
Full history
Code Snippet
git log
Short history
Code Snippet
git log --oneline
Graph history
Code Snippet
git log --oneline --graph --all
9. Branching đŗ
Create branch
Code Snippet
git branch feature-auth
View branches
Code Snippet
git branch
Switch branch
Code Snippet
git checkout feature-auth
Modern alternative:
Code Snippet
git switch feature-auth
Create + switch
Code Snippet
git checkout -b feature-auth
or
Code Snippet
git switch -c feature-auth
10. Merge Branches
Switch to main:
Code Snippet
git checkout main
Merge:
Code Snippet
git merge feature-auth
11. Delete Branch
Code Snippet
git branch -d feature-auth
Force delete:
Code Snippet
git branch -D feature-auth
12. Remote Repository đ
Add remote
Code Snippet
git remote add origin REPO_URL
View remotes
Code Snippet
git remote -v
13. Push Code
First push
Code Snippet
git push -u origin main
Normal push
Code Snippet
git push
14. Clone Repository
Code Snippet
git clone REPO_URL
15. Pull Latest Changes
Code Snippet
git pull
Equivalent to:
Code Snippet
git fetch git merge
16. Fetch Changes
Code Snippet
git fetch
Downloads changes without merging.
17. Git Diff đ
Unstaged changes
Code Snippet
git diff
Staged changes
Code Snippet
git diff --staged
18. Undo Changes
Remove unstaged changes
Code Snippet
git restore app.js
Unstage file
Code Snippet
git restore --staged app.js
19. Reset Commits â ī¸
Soft reset
Keeps changes.
Code Snippet
git reset --soft HEAD~1
Hard reset
Deletes changes.
Code Snippet
git reset --hard HEAD~1
20. Revert Commit
Safe undo:
Code Snippet
git revert COMMIT_ID
21. Stash Changes đĻ
Temporarily save work.
Save stash
Code Snippet
git stash
View stash
Code Snippet
git stash list
Apply stash
Code Snippet
git stash apply
Remove stash
Code Snippet
git stash drop
22. Rename Branch
Current branch
Code Snippet
git branch -m new-name
23. Tags đˇī¸
Create tag
Code Snippet
git tag v1.0
Push tags
Code Snippet
git push origin --tags
24. Git Ignore đĢ
Create .gitignore
Example:
Code Snippet
node_modules/ .env dist/
25. Remove File from Git
Code Snippet
git rm file.txt
Keep local file:
Code Snippet
git rm --cached file.txt
26. Cherry Pick đ
Copy commit from another branch:
Code Snippet
git cherry-pick COMMIT_ID
27. Rebase đ§Ŧ
Cleaner history.
Code Snippet
git rebase main
Interactive:
Code Snippet
git rebase -i HEAD~3
28. View Who Changed What
Code Snippet
git blame app.js
Git detective mode đĩī¸
29. Clean Untracked Files
Code Snippet
git clean -f
Folders too:
Code Snippet
git clean -fd
30. Git Aliases âĄ
Example:
Code Snippet
git config --global alias.s status
Now use:
Code Snippet
git s
31. SSH Authentication đ
Generate SSH key:
Code Snippet
ssh-keygen -t ed25519 -C "you@example.com"
Test:
Code Snippet
ssh -T git@github.com
32. Advanced Log
Code Snippet
git log --all --decorate --oneline --graph
Beautiful commit tree đ˛
33. Useful Daily Workflow
Code Snippet
git pull git checkout -b feature git add . git commit -m "Feature added" git push origin feature
34. Fix Merge Conflicts âī¸
Conflict markers:
Code Snippet
<<<<<<< HEAD Current code ======= Incoming code >>>>>>> branch
Steps:
Code Snippet
git add . git commit
35. GitHub Workflow
Code Snippet
git clone URL git checkout -b feature git add . git commit -m "New feature" git push origin feature
Then create Pull Request.
36. Git Command Cheat Sheet đ
| Command | Purpose |
|---|---|
| git init | Initialize repo |
| git clone | Copy repo |
| git status | Check changes |
| git add . | Stage files |
| git commit | Save snapshot |
| git push | Upload changes |
| git pull | Download changes |
| git branch | List branches |
| git checkout | Switch branch |
| git merge | Merge branches |
| git stash | Temporary save |
| git reset | Undo commits |
| git revert | Safe undo |
| git log | View history |
37. Recommended Learning Order đ§
Code Snippet
1. init 2. status 3. add 4. commit 5. log 6. branch 7. merge 8. remote 9. push/pull 10. stash/reset/rebase
38. Golden Rules â¨
- Commit small changes
- Write clear commit messages
- Pull before push
- Never force push blindly
- Use branches for features
- Keep .env inside .gitignore
39. Pro Developer Commands đ§
See remote branches
Code Snippet
git branch -a
Show one commit
Code Snippet
git show COMMIT_ID
Amend last commit
Code Snippet
git commit --amend
Force push
Code Snippet
git push --force
Danger dragon đ Use carefully.
40. Real Mental Model đ
Code Snippet
Git â file storage Git = timeline management system
You are not editing files.
You are sculpting history. đĒ