Git Commands Cheat Sheet: 15 Essential Git Commands Every Developer Must Know

Git is one of the most powerful version control systems used by developers worldwide. Whether you’re working solo or collaborating in a team, mastering Git commands is essential for efficient code management.

In this guide, you’ll learn 15 essential Git commands with examples, helping you streamline your development workflow and avoid common mistakes.

🔹 1. git clone (Copy a Repository)

The git clone command is used to download a remote repository to your local machine.

git clone https://github.com/user/project.git

👉 This creates a complete local copy of the project, including all files and commit history.

🔹 2. git status (Check Repository Status)

This command shows the current state of your working directory.

git status

👉 It helps you identify:

  • Modified files
  • Staged files
  • Untracked files

🔹 3. git add (Stage Changes)

Before committing, you need to stage your changes.

git add file.txt

To add all files:

git add .

👉 Moves changes to the staging area.


🔹 4. git commit (Save Changes)

Commits save your staged changes with a message.

git commit -m "Added login feature"

👉 Think of it as creating a checkpoint in your project.


🔹 5. git push (Upload Code to Remote)

Push your local commits to a remote repository.

git push origin main

👉

  • origin = remote repository
  • main = branch name

🔹 6. git pull (Get Latest Code)

Fetches and merges the latest changes from the remote repository.

git pull origin main

👉 Best practice: Always pull before starting work to avoid conflicts.


🔹 7. git fetch (Download Changes Only)

Downloads changes without merging.

git fetch

👉 Useful for safely reviewing updates before applying them.


🔹 8. git branch (Manage Branches)

List all branches:

git branch

Create a new branch:

git branch feature-login

👉 Helps in working on features independently.


🔹 9. git checkout (Switch Branches)

Switch to another branch:

git checkout feature-login

Create and switch:

git checkout -b feature-login

👉 Used for navigation and restoring files.


🔹 10. git merge (Combine Branches)

Merge one branch into another.

git checkout main
git merge feature-login

👉 Integrates feature code into the main branch.


🔹 11. git log (View Commit History)

Shows commit history.

git log

Short version:

git log --oneline

👉 Helps track changes and history.


🔹 12. git diff (See Code Changes)

Displays differences between files.

git diff

👉 Useful for reviewing changes before committing.


🔹 13. git reset (Undo Staging)

Remove a file from staging area:

git reset file.txt

👉 Does not delete changes, only unstages them.


🔹 14. git stash (Save Work Temporarily)

Save unfinished work:

git stash

Restore it later:

git stash pop

👉 Perfect when switching branches without committing.


🔹 15. git remote (Manage Remote Repositories)

View remote repositories:

git remote -v

Add a new remote:

git remote add origin https://github.com/user/project.git

⚠️ Important Git Workflow Tip (Real-World Practice)

👉 Before pushing code:

  • Always pull from pencil_dev_env
  • Only push to basant_dev
  • Add proper tags when required

This ensures:

  • No merge conflicts
  • Clean collaboration
  • Proper version tracking

📌 Best Practices for Using Git

  • ✅ Commit frequently with meaningful messages
  • ✅ Pull before starting work
  • ✅ Use branches for new features
  • ✅ Avoid pushing directly to main
  • ✅ Use git fetch for safe updates
  • ✅ Keep your repository clean

🎯 Conclusion

Mastering these Git commands will significantly improve your development workflow. Whether you’re a beginner or an experienced developer, these commands form the foundation of efficient version control.

Start practicing today and make Git your best development companion 🚀