DEV Community

Cover image for Git: 50 Essential Commands for Everyday Workflow
Ahmed Niazy
Ahmed Niazy

Posted on

11 3 2 1 1

Git: 50 Essential Commands for Everyday Workflow

Git is a distributed version control system (DVCS) created by Linus Torvalds in 2005 to manage the Linux kernel’s source code. Unlike centralized systems, Git keeps a complete history of your project on every developer’s machine, making it easy to revert, branch, and merge changes no matter your workflow.

Below is a reorganized, step-by-step guide to the 50 Git commands you’ll use most often, grouped by category. You’ll find concise explanations, usage examples, and tips so you can copy-and-paste as you learn.


📋 1. Configuration

Before you start, tell Git who you are:

# View all settings (name, email, cache, editor, etc.)
git config -l

# Set your name (appears in commits)
git config --global user.name "Your Name"

# Set your email (appears in commits)
git config --global user.email "you@example.com"

# Cache HTTPS credentials (default: 15 minutes)
git config --global credential.helper cache

# Change the cache timeout (in seconds), e.g., 1 hour:
git config --global credential.helper 'cache --timeout=3600'
Enter fullscreen mode Exit fullscreen mode

🌱 2. Creating a Repository

Initialize a new project:

# In your project folder, start tracking with Git
git init
Enter fullscreen mode Exit fullscreen mode

➕ 3. Staging Changes

Prepare your work for committing:

# Add ONE file
git add filename.txt

# Add ALL files (new, modified, deleted)
git add .

# Add only files matching a pattern, e.g., all “app-” files
git add app-*

# Interactive staging: choose hunks to stage
git add -p
Enter fullscreen mode Exit fullscreen mode

✔️ 4. Checking Status & Differences

Inspect what you’ve modified:

# Show staged vs. unstaged vs. untracked
git status

# Show unstaged changes in working directory
git diff

# Show staged changes ready to commit
git diff --staged

# Show changes for a specific file
git diff path/to/file.py
Enter fullscreen mode Exit fullscreen mode

💾 5. Committing

Record your changes in project history:

# Open your editor to write a multi-line message
git commit

# One-line commit message
git commit -m "Short summary of changes"

# Stage AND commit modified files in one go
git commit -a -m "Fix typo in README"
Enter fullscreen mode Exit fullscreen mode

📜 Viewing Commit History

# Simple log
git log

# Log with patch (diffs)
git log -p

# Log with stats (lines and file names changed)
git log --stat

# One-line, ASCII graph of commits
git log --graph --oneline
Enter fullscreen mode Exit fullscreen mode

🔍 Inspecting a Single Commit

# Show full details of a specific commit
git show <commit-hash>
Enter fullscreen mode Exit fullscreen mode

🔄 6. Undoing & Amending

# Revert unstaged changes in working directory
git checkout -- filename.txt

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

# Unstage interactively
git reset -p

# Amend last commit (modify message or include new changes)
git commit --amend

# Create a “reverting” commit that undoes a specific commit
git revert <commit-hash>

# Roll back latest commit by reverting HEAD
git revert HEAD
Enter fullscreen mode Exit fullscreen mode

⚠️ Caution: Avoid --amend on commits you’ve already pushed, as rewriting history can confuse collaborators.


🌿 7. Branching & Merging

# List all local branches
git branch

# Create a new branch
git branch feature/login

# Switch to another branch
git checkout feature/login

# Create + switch in one command
git checkout -b feature/signup

# Delete a local branch (after merging)
git branch -d old-branch

# Merge another branch into your current one
git merge feature/login

# Abort a conflicted merge
git merge --abort
Enter fullscreen mode Exit fullscreen mode

🔗 8. Working with Remotes

Link your local repo to a shared server (GitHub, GitLab, Bitbucket):

# Add a remote named “origin”
git remote add origin https://github.com/you/repo.git

# List remote URLs
git remote -v

# Show detailed info about a remote
git remote show origin

# Download from remote without merging
git fetch

# Download + merge (shorthand)
git pull

# Upload commits to remote
git push

# Push a new branch and set upstream
git push -u origin feature/login

# Delete a remote branch
git push --delete origin old-branch
Enter fullscreen mode Exit fullscreen mode

🔄 9. Rebasing (Advanced)

Rebase lets you “replay” commits from one branch onto another:

# Non-interactive rebase onto master
git rebase master

# Interactive rebase (reorder, squash, edit)
git rebase -i master
Enter fullscreen mode Exit fullscreen mode

Tip: Rebasing gives you a cleaner, linear history—but avoid rebasing public branches.


🎯 10. Miscellaneous Tips

# View remote-tracking branches
git branch -r

# Show log of remote main branch
git log origin/main

# Update all remotes without merging
git remote update

# Force-push (careful: overwrites remote!)
git push -f
Enter fullscreen mode Exit fullscreen mode

🚀 Conclusion

With these 50 commands, you have a solid foundation to:

  • Configure Git for your identity
  • Stage and commit changes efficiently
  • Branch, merge, and even rebase safely
  • Collaborate using remotes and pull/push workflows

Bookmark this list, try them in a test repo, and soon they’ll become second nature. Happy coding!

Dynatrace image

Frictionless debugging for developers

Debugging in production doesn't have to be a nightmare.

Dynatrace reimagines the developer experience with runtime debugging, native OpenTelemetry support, and IDE integration allowing developers to stay in the flow and focus on building instead of fixing.

Learn more

Top comments (4)

Collapse
 
nevodavid profile image
Nevo David

Pretty cool, having all the main commands in one spot honestly makes life easier for me.

Collapse
 
sejutaimpian profile image
Eris Sulistina

Nice Post!

Collapse
 
muhammedhossam profile image
Muhammed Hossam

Useful ❤️

Collapse
 
dotallio profile image
Dotallio

Super helpful breakdown! Cheat sheets like this save me from making silly mistakes, do you have any tricks for dealing with tricky merge conflicts?

Tiger Data image

🐯 🚀 Timescale is now TigerData: Building the Modern PostgreSQL for the Analytical and Agentic Era

We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.

So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.

Read more

👋 Kindness is contagious

Explore this compelling article, highly praised by the collaborative DEV Community. All developers, whether just starting out or already experienced, are invited to share insights and grow our collective expertise.

A quick “thank you” can lift someone’s spirits—drop your kudos in the comments!

On DEV, sharing experiences sparks innovation and strengthens our connections. If this post resonated with you, a brief note of appreciation goes a long way.

Get Started