Essential Git Commands with Explanation
Basic Git Commands
git init - Initialize a new Git repository
git clone <url> - Clone a repository into a new directory
git status - Show the working tree status
git add <file> - Add file contents to the index (staging)
git add . - Add all files to staging
git commit -m "" - Commit staged changes with a message
git log - Show commit logs
git config - Set Git configuration (username/email)
Branching & Merging
git branch - List branches
git branch <name> - Create a new branch
git checkout <name>- Switch to a branch
git switch <name> - Modern alternative to checkout
git merge <branch> - Merge a branch into current branch
Remote Repositories
git remote -v - Show remote URLs
git remote add origin <url> - Add a remote repository
git push -u origin main - Push first commit and set upstream
git push - Push local commits to remote
git pull - Fetch and merge changes from remote
git fetch - Download changes without merging
Undo / Reset / Fix
Essential Git Commands with Explanation
git restore <file> - Restore file to last committed state
git reset - Unstage a file
git revert <commit> - Revert a specific commit
git stash - Save current changes temporarily
git stash pop - Apply stashed changes
Extra Helpful Commands
git show - Show details of last commit
git diff - Show changes between commits/files
git tag - Create a version tag (e.g., v1.0.0)
git cherry-pick <commit> - Apply changes from a specific commit
git rm <file> - Delete file from working directory and Git