JS Guide
HomeQuestionsSearchResources
Search

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionstooling
Prev
tooling
junior
version-control

What are the essential Git commands every developer should know?

git
version-control
commands
workflow
Quick Answer

Essential Git commands include: clone (copy repo), add/commit (save changes), push/pull (sync with remote), branch/checkout (manage branches), merge (combine branches), and status/log (view state). Understanding these enables effective collaboration.

Detailed Explanation

Basic Workflow:

  1. Clone or init repository
  2. Make changes
  3. Stage changes (add)
  4. Commit changes
  5. Push to remote

Key Concepts:

  • Working directory → Staging → Repository
  • Branches for parallel development
  • Remote for collaboration
  • Commits are snapshots

Essential Commands:

  • Setup: clone, init, config
  • Changes: add, commit, status, diff
  • Branches: branch, checkout, merge
  • Remote: push, pull, fetch
  • History: log, show

Code Examples

Essential Git commands
# Setup
git clone <url>           # Copy repository
git init                  # Create new repo
git config --global user.name "Name"
git config --global user.email "email@example.com"

# Basic workflow
git status                # See changes
git add .                 # Stage all changes
git add file.js           # Stage specific file
git commit -m "message"   # Commit changes
git push                  # Push to remote
git pull                  # Get latest changes

# Branches
git branch                # List branches
git branch feature        # Create branch
git checkout feature      # Switch branch
git checkout -b feature   # Create and switch
git merge feature         # Merge branch
git branch -d feature     # Delete branch

# Viewing history
git log                   # Commit history
git log --oneline         # Compact history
git diff                  # Unstaged changes
git diff --staged         # Staged changes

Resources

Git Documentation

docs

GitHub Git Cheat Sheet

docs

Related Questions

What is npm and how do you manage packages with it?

junior
package-managers
Previous
What is Vite and why is it faster than traditional bundlers?