Skip to content
Developer2026-05-314 min read

Essential Git Commands: A Developer's Quick Reference

Git Essentials

Git is the standard version control system for software development. This guide covers the commands every developer needs to know, organized by workflow.

Setup and Configuration

# Initialize a new repository
git init

# Clone an existing repository
git clone https://github.com/user/repo.git

# Configure your identity
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Staging and Committing

# Check status of working directory
git status

# Stage a file
git add filename.txt

# Stage all changes
git add .

# Unstage a file
git reset HEAD filename.txt

# Commit staged changes
git commit -m "Describe your change"

# Amend the last commit (message or files)
git commit --amend -m "Updated message"

Try It: Git Cheatsheet

Use our Git Cheatsheet for a quick reference of common Git commands.

Branching

# List all branches
git branch

# Create a new branch
git branch feature-name

# Switch to a branch
git checkout feature-name

# Create and switch in one command
git checkout -b feature-name

# Delete a branch (after merging)
git branch -d feature-name

# Force delete an unmerged branch
git branch -D feature-name

Merging and Rebasing

Merging

# Merge a branch into current branch
git merge feature-branch

# Merge with no fast-forward (preserves branch history)
git merge --no-ff feature-branch

Rebasing

# Rebase current branch onto main
git rebase main

# Interactive rebase (squash, edit, reorder commits)
git rebase -i HEAD~3

When to rebase vs. merge:

  • Merge: Preserves complete history, safe for shared branches
  • Rebase: Creates linear history, only for local/unshared branches

Resolving Conflicts

When Git can't automatically merge changes, you get conflicts:

# 1. See which files have conflicts
git status

# 2. Edit conflicted files
# Look for markers:
# <<<<<<< HEAD
# your changes
# =======
# their changes
# >>>>>>> feature-branch

# 3. After resolving, stage the file
git add resolved-file.txt

# 4. Complete the merge
git commit

Use our Diff Checker to compare text and find differences.

Remote Operations

# Add a remote
git remote add origin https://github.com/user/repo.git

# Push to remote
git push origin main

# Pull from remote
git pull origin main

# Fetch without merging
git fetch origin

# See remote URLs
git remote -v

Viewing History

# Show commit log
git log

# Compact one-line log
git log --oneline

# Show log with file changes
git log --stat

# Show a specific commit
git show abc1234

# Compare two branches
git diff main..feature

Undoing Changes

# Undo changes in working directory (keep staging)
git checkout -- filename.txt

# Unstage a file (keep changes)
git reset HEAD filename.txt

# Undo last commit (keep changes staged)
git reset --soft HEAD~1

# Undo last commit (keep changes unstaged)
git reset HEAD~1

# DANGER: Completely discard everything
git reset --hard HEAD~1

Stashing

# Stash current changes
git stash

# Stash with a message
git stash save "work in progress"

# List stashes
git stash list

# Apply most recent stash
git stash pop

# Apply a specific stash
git stash apply stash@{2}

# Drop a stash
git stash drop stash@{0}

Tagging

# Create a lightweight tag
git tag v1.0.0

# Create an annotated tag
git tag -a v1.0.0 -m "Release version 1.0.0"

# List tags
git tag

# Push tags to remote
git push origin --tags

# Delete a tag
git tag -d v1.0.0

Developer Tools That Complement Git

Git Workflow Best Practices

  1. Commit often: Small, focused commits are easier to review and revert
  2. Write good messages: Start with a verb: "Add", "Fix", "Update", "Remove"
  3. Use branches: Never commit directly to main/master
  4. Pull before push: Always git pull before pushing to avoid conflicts
  5. Review before committing: Use git diff to check changes before staging

Conclusion

Git is essential for every developer. Bookmark our Git Cheatsheet and use the Diff Checker when resolving merge conflicts.

Try our free developer tools

All tools run in your browser with zero data uploads.

← Back to Blog