Skip to main content

Whether you’re working on Drupal, WordPress, or any custom PHP project, Git is the most powerful tool for version control and collaboration.
In this blog, we’ll explore the most commonly used Git commands, so you can manage your projects like a pro.

🔹 1. Git Setup

Before you start, configure Git with your details:

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

This ensures every commit is linked to your identity.


🔹 2. Starting a Project

 
# Initialize Git in a project
git init

# Clone a remote project
git clone https://github.com/user/repo.git

🔹 3. Checking Project Status

git status   # See which files are changed
git diff     # Show exact code differences

🔹 4. Adding & Committing Changes

git add .                      # Stage all files
git commit -m "Added new feature"  # Save changes

🔹 5. Working with Branches

Branches help you work on new features safely:

git branch feature-login        # Create a branch
git checkout feature-login      # Switch to it
git checkout -b bugfix-header   # Create & switch

Merge branches into main:

 
git checkout main
git merge feature-login

🔹 6. Pushing & Pulling Code

git push origin main   # Upload changes
git pull origin main   # Download updates

🔹 7. Undoing Changes

git checkout -- file.php        # Undo file changes
git reset file.php              # Unstage file
git reset --soft HEAD~1         # Undo last commit, keep changes
git reset --hard HEAD~1         # Undo last commit, delete changes

🔹 8. Checking History

git log --oneline --graph --all

This shows a visual history of commits and branches.


🔹 9. Git & Drupal/WordPress Projects

When working with Drupal or WordPress, remember to:

  • Commit only custom modules/themes and configuration.

  • Ignore vendor/, node_modules/, and cache files.

  • For Drupal, use:

drush cex -y   # Export config
git add config/sync/
git commit -m "Updated Drupal config"

✅ Final Thoughts

Git is a must-have for every developer. By mastering these commands, you can:

  • Keep your codebase clean

  • Collaborate easily with your team

  • Roll back changes safely

  • Deploy projects faster

👉 Whether you’re building a Drupal site, WordPress theme, or custom PHP app, these Git commands will make your workflow smoother and more professional.