| ๐ง Git Configuration |
| git config --global user.name "Name" | Set your Git username globally | git config --global user.name "Manoj" |
| git config --global user.email "email@example.com" | Set your Git email globally | git config --global user.email "manoj@example.com" |
| ๐ Start a Working Area |
| git init | Initialize a new Git repository | git init |
| git clone <repo-url> | Clone a remote repository locally | git clone https://github.com/user/repo.git |
| ๐ ๏ธ Work on the Current Change |
| git status | Show current repo status (changes, branch) | git status |
| git add <file> | Stage a file for commit | git add README.md |
| git add . | Stage all changes | git add . |
| git mv <old> <new> | Move or rename a file, directory, or symlink | git mv old.txt new.txt |
| git restore <file> | Restore working tree files | git restore index.html |
| git rm <file> | Remove files from the working tree and index | git rm index.html |
| โ
Committing Changes |
| git commit -m "message" | Commit staged changes with message | git commit -m "Initial commit" |
| git commit -m "msg" | Record changes to the repository | git commit -m "Add new feature" |
| ๐ History & State |
| git log | Show commit history | git log |
| git log --oneline --all | Show all commits in all branches, brief | git log --oneline --all |
| git show | Show various types of objects (commits, tags, etc.) | git show HEAD |
| git diff | Show changes between commits or working tree | git diff HEAD~1 HEAD |
| git grep "text" | Search tracked files for a string or pattern | git grep "function" |
| git reflog | Show recent HEAD movements (recover commits) | git reflog |
| git bisect | Find the commit that introduced a bug using binary search | git bisect start |
| ๐ฟ Branching |
| git branch | List all local branches | git branch |
| git branch -a | List all branches (local + remote) | git branch -a |
| git branch -d <branch-name> | Delete a local branch | git branch -d feature-x |
| git switch <branch> | Switch branches | git switch feature |
| git checkout <branch-name> | Switch to a branch | git checkout master |
| git checkout -b <new-branch> | Create and switch to new branch | git checkout -b feature-x |
| ๐ Merging & Rebasing |
| git merge <branch> | Join two or more development histories together | git merge dev |
| git merge <branch-name> | Merge another branch into current | git merge feature-x |
| git rebase <base> | Reapply commits on top of another base tip | git rebase main |
| โป๏ธ Reset, Revert & Stash |
| git reset --soft <commit-id> | Move branch pointer, keep staged changes | git reset --soft 5b5139a |
| git reset --mixed <commit-id> | Move branch pointer, keep unstaged changes | git reset --mixed 5b5139a |
| git reset --hard <commit-id> | Move branch pointer, discard changes | git reset --hard 5b5139a |
| git reset --hard <commit> | Reset current HEAD to the specified state | git reset --hard HEAD~1 |
| git revert <commit-id> | Undo a commit by creating a new commit | git revert 5b5139a |
| git stash | Temporarily save uncommitted changes | git stash |
| git stash pop | Apply stashed changes back | git stash pop |
| ๐ท๏ธ Tagging |
| git tag <tagname> | Create a tag | git tag v1.0 + git push origin v1.0 |
| ๐ Remote Setup |
| git remote add origin <url> | Adds a remote named origin pointing to your repo | git remote add origin https://github.com/username/repo.git |
| git remote -v | Verifies the remote URL(s) | git remote -v |
| git push -u origin <branch> | Pushes code to remote and sets upstream tracking | git push -u origin master |
| git remote remove origin | Removes the remote named origin | git remote remove origin |
| git remote rename <old> <new> | Renames a remote | git remote rename origin upstream |
| git remote set-url origin <new-url> | Changes the URL of a remote | git remote set-url origin https://new.url/repo.git |
| ๐ Push / Pull / Fetch |
| git fetch | Download objects and refs from another repository | git fetch origin |
| git pull origin <branch> | Fetch & merge remote changes | git pull origin master |
| git pull | Fetch from and integrate with another repository | git pull origin main |
| git push origin <branch> | Push a branch to remote | git push origin master |
| git push -u origin <branch> | Push & track remote branch | git push -u origin feature-x |
| git push --all origin | Push all local branches to remote | git push --all origin |
| git push origin --delete <branch> | Delete a remote branch | git push origin --delete feature-x |
| ๐ Backfill |
| git backfill | Download missing objects in a partial clone | git backfill |
| ๐ Checkout Specific Commit |
| git checkout <commit-id> | Switch to a specific commit (detached HEAD) | git checkout 5b5139a |
| โ๏ธ Git Configuration Utilities |
| git config --list | List all Git configurations | git config --list |
| ๐งน Cleaning Up |
| git clean -n | Show files that would be removed (dry run) | git clean -n |
| git clean -f | Remove untracked files from the working directory | git clean -f |
| git fetch -p | Prune deleted remote branches | git fetch -p |
| โ๏ธ Amend a Commit |
| git commit --amend | Modify the last commit (message or files) | git commit --amend -m "Updated message" |
| ๐ Cherry Pick |
| git cherry-pick <commit-id> | Apply a commit from another branch | git cherry-pick a1b2c3d |
| git revert HEAD~2..HEAD | Revert a range of commits | git revert HEAD~2..HEAD |
| ๐ท๏ธ Git Aliases |
| git config --global alias.co checkout | Create a shortcut (alias) for a command | git co master |