🌟 Essential Git Commands

Repository Setup

# Initialize a new repository
git init

# Clone an existing repository
git clone [repository-url]

# Add remote repository
git remote add origin [repository-url]

📝 Daily Workflow

Basic Commands

# Check status
git status

# Add files to staging
git add [file-name]
git add .  # Add all changes

# Commit changes
git commit -m "your message"

# Push changes
git push origin [branch-name]

# Pull changes
git pull origin [branch-name]

đŸŒŋ Branch Management

# Create new branch
git branch [branch-name]

# Switch to branch
git checkout [branch-name]

# Create and switch in one command
git checkout -b [branch-name]

# List branches
git branch -a

# Delete branch
git branch -d [branch-name]

🔄 Merging & Rebasing

# Merge branch into current branch
git merge [branch-name]

# Rebase current branch
git rebase [branch-name]

# Interactive rebase
git rebase -i HEAD~[number-of-commits]

â†Šī¸ Undoing Changes

# Discard changes in working directory
git checkout -- [file-name]

# Reset staged changes
git reset HEAD [file-name]

# Soft reset (keep changes in staging)
git reset --soft HEAD^

# Hard reset (discard all changes)
git reset --hard HEAD^

# Create new commit that undoes previous commit
git revert HEAD

🔍 Inspection & Comparison

# View commit history
git log

# Show changes in commit
git show [commit-hash]

# View file differences
git diff [file-name]

# View staged differences
git diff --staged

💡 Pro Tips

  • Use git stash to temporarily save changes
  • Create aliases for common commands in .gitconfig
  • Use git commit --amend to modify last commit
  • Add --no-verify to skip pre-commit hooks
  • Use git cherry-pick to apply specific commits