Git & GitHub Command Sheet
1. Setup & Configuration
● git config --global [Link] "Your Name" → Set your Git username
● git config --global [Link] "you@[Link]" → Set your Git email
● git config --list → Show all Git configurations
2. Starting a Repository
● git init → Initialize a new Git repository
● git clone <repo-url> → Clone a remote repository
3. Basic Snapshotting
● git status → Check status of changes
● git add <file> → Stage a file
● git add . → Stage all changes
● git commit -m "Commit message" → Commit staged changes
● git log → View commit history
● git log --oneline --graph --decorate --all → Visualize history
● git diff → See unstaged changes
● git diff --staged → See staged changes
4. Branching & Merging
● git branch → List branches
● git branch <branch-name> → Create new branch
● git checkout <branch-name> → Switch to a branch
● git switch <branch-name> → Alternative to checkout (newer)
● git merge <branch-name> → Merge a branch into current branch
● git branch -d <branch-name> → Delete a branch
5. Working with Remote Repos
● git remote -v → Show remotes
● git remote add origin <url> → Add a new remote
● git push origin <branch> → Push branch to remote
● git pull origin <branch> → Pull updates from remote
● git fetch → Download changes without merging
6. Undoing & Resetting
● git restore <file> → Discard local changes (unstaged)
● git reset HEAD <file> → Unstage a file
● git reset --hard → Reset all changes to last commit
● git revert <commit-id> → Create a new commit that reverts changes
7. Stashing
● git stash → Save changes temporarily
● git stash apply → Reapply stashed changes
● git stash list → List stashes
● git stash drop → Remove a stash
8. Collaboration
● Forking (GitHub UI) → Copy someone’s repo
● git clone <fork-url> → Clone your fork
● git checkout -b <branch> → Create a new feature branch
● git push origin <branch> → Push changes to your fork
● Open Pull Request (PR) on GitHub
9. Advanced Git Commands
Rebasing & History
● git rebase <branch> → Reapply commits on top of another branch
● git rebase -i HEAD~n → Interactive rebase (edit/squash commits)
● git reflog → Show history of HEAD movements
Cherry-Picking
● git cherry-pick <commit-id> → Apply a specific commit from another branch
Tags
● git tag → List tags
● git tag <tag-name> → Create a new tag
● git push origin <tag-name> → Push a tag to remote
Submodules
● git submodule add <repo-url> → Add a submodule
● git submodule update --init --recursive → Initialize/update submodules
Cleaning
● git clean -n → Preview files to be removed
● git clean -f → Remove untracked files
📌 Best YouTube Channels to Learn Git
1. Chai aur Code Link
2. Kunal Kushwaha Link
3. Apna College Link
4. Shreyians Coding Link
5. Telusko Link