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 status
    Example: git status to see which files are staged, unstaged, or untracked.
  • git branch – List, create, or delete branches
    Example: git branch feature/login to create a new branch for a login feature.
  • git checkout – Switch branches or restore files
    Example: git checkout main to 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 repository
    Example: git commit -m \"Fix login bug\" to save your staged changes with a message.
  • git log – Show commit logs
    Example: git log --oneline to see a concise history of commits.
  • git rm – Remove files from the working tree and from the index
    Example: git rm obsolete.txt to remove a file from your project and stage the removal.
Merging, History & Collaboration
  • git merge – Join two or more development histories
    Example: git merge feature/login to merge the login feature branch into your current branch.
  • git rebase – Reapply commits on top of another base tip
    Example: git rebase main to update your branch with the latest changes from main.
  • git reset – Reset current HEAD to the specified state
    Example: git reset --hard HEAD~1 to undo the last commit and all changes.
  • git diff – Show changes between commits, commit and working tree, etc.
    Example: git diff feature/login..main to compare changes between two branches.
  • git stash – Stash the changes in a dirty working directory
    Example: git stash to temporarily save your uncommitted changes.
  • git pull – Fetch from and integrate with another repository or a local branch
    Example: git pull origin main to update your local branch with remote changes.
  • git push – Update remote refs along with associated objects
    Example: git push origin feature/login to upload your branch to the remote repository.