Guide
Git Commands Guide
Essential CLI Reference for Developers
Master the most important git commands for daily development. This guide covers branch management, commit history, merging, rebasing, and more, with practical examples for every workflow.
Branch & Commit
git status– Show working tree statusExample:git statusto see which files are staged, unstaged, or untracked.git branch– List, create, or delete branchesExample:git branch feature/loginto create a new branch for a login feature.git checkout– Switch branches or restore filesExample:git checkout mainto switch back to the main branch.git add– Add file contents to the index (staging area)Example:git add .to stage all modified and new files for commit.git commit– Record changes to the repositoryExample:git commit -m \"Fix login bug\"to save your staged changes with a message.git log– Show commit logsExample:git log --onelineto see a concise history of commits.git rm– Remove files from the working tree and from the indexExample:git rm obsolete.txtto remove a file from your project and stage the removal.
Merging, History & Collaboration
git merge– Join two or more development historiesExample:git merge feature/loginto merge the login feature branch into your current branch.git rebase– Reapply commits on top of another base tipExample:git rebase mainto update your branch with the latest changes from main.git reset– Reset current HEAD to the specified stateExample:git reset --hard HEAD~1to undo the last commit and all changes.git diff– Show changes between commits, commit and working tree, etc.Example:git diff feature/login..mainto compare changes between two branches.git stash– Stash the changes in a dirty working directoryExample:git stashto temporarily save your uncommitted changes.git pull– Fetch from and integrate with another repository or a local branchExample:git pull origin mainto update your local branch with remote changes.git push– Update remote refs along with associated objectsExample:git push origin feature/loginto upload your branch to the remote repository.