Git Workflow Documentation

Complete guide to Git commands, branching strategies, and team collaboration workflows.

Quick Reference Commands

git status

Check repository status

git pull

Pull latest changes

git add .

Stage all changes

git commit -m "msg"

Commit changes

git push

Push to remote

git checkout -b feature/name

Create feature branch

RPTPL Backend Server - Git Workflow

🌳 Branch Strategy

main Main production branch
feature/* New features development
bugfix/* Bug fixes for issues
hotfix/* Urgent production fixes

🔄 Daily Workflow

  1. 1 git checkout main && git pull
  2. 2 git checkout -b feature/your-work
  3. 3 Make changes, commit regularly
  4. 4 git push & create Pull Request

Commit Message Conventions

Standard format for commit messages in this project.

Message Format

<type>: <subject> <optional description> <optional footer>

All commit messages must follow this format with proper type prefix.

Commit Types

feat:

New feature for the user

fix:

Bug fix for the user

docs:

Documentation changes

style:

Code style changes (formatting)

refactor:

Code refactoring (no functional change)

test:

Adding or updating tests

chore:

Build process, tools, dependencies

perf:

Performance improvements

Examples

✅ Good commit messages:

feat: add OAuth2 authentication for mobile apps fix: resolve null pointer in user registration docs: update API endpoint documentation refactor: optimize database query for metadata

❌ Bad commit messages:

updates fixed bug stuff wip

Message Guidelines

  • Use imperative mood ("add feature" not "added feature")
  • Limit first line to 50 characters or less
  • Reference issue numbers when applicable (e.g., "fix: #123")
  • Make atomic commits (one logical change per commit)
  • Never commit debug code (dd(), console.log, var_dump)

Pre-Commit Hooks

Automated quality checks that run before every commit.

What Pre-Commit Hooks Check

PHP Syntax Validation

Checks all staged PHP files for syntax errors using php -l

Debug Code Detection

Scans for debug statements like dd(), dump(), var_dump()

Sensitive File Detection

Prevents committing sensitive files like .env, .pem, .key

Merge Conflict Detection

Checks for unresolved merge conflicts (<<<<<<< HEAD)

Test Isolation Detection

Prevents committing test files with ->only() (single test isolation)

Bypassing Hooks (Use Carefully!)

⚠️ Warning: Only bypass hooks when absolutely necessary. Make sure your code passes quality checks manually.

# Commit without hook checks git commit --no-verify -m "your message" # Or use npm scripts npm run commit:bypass npm run commit:bypass:push

Managing Hooks

npm run hooks:install

Install pre-commit hooks

npm run hooks:install:windows

Install hooks on Windows

npm run hooks:uninstall

Remove all hooks

.git/hooks/pre-commit

Hook file location

Basic Git Commands

Essential commands for everyday Git operations.

Repository Setup

git init Initialize a new Git repository
git clone <url> Clone an existing repository
git status Check repository status

Basic Operations

git add <file> Stage a file for commit
git add . Stage all changes
git commit -m "message" Commit staged changes
git commit -am "message" Commit all changes (modified files only)
git commit --amend Modify the last commit

Push & Pull

git push Push commits to remote
git push origin main Push to specific branch
git push -u origin <branch> Push and set upstream
git pull Pull and merge changes from remote
git pull --rebase Pull with rebase instead of merge
git fetch Fetch changes without merging

Branching Strategy

Branch management, merging, and rebasing workflows.

Branch Management

git branch List all branches
git branch <branch-name> Create new branch
git branch -d <branch-name> Delete branch (merged)
git branch -D <branch-name> Delete branch (force)
git checkout <branch-name> Switch to branch
git checkout -b <branch-name> Create and switch branch
git switch <branch-name> Modern way to switch branches
git switch -c <branch-name> Modern way to create branch

Merging

git merge <branch-name> Merge branch into current
git merge --no-ff <branch> Merge with commit always
git merge --abort Abort current merge

Rebasing

git rebase <branch-name> Rebase current branch
git rebase -i HEAD~3 Interactive rebase last 3 commits
git rebase --continue Continue rebase
git rebase --abort Abort rebase

Branch Strategies

feature/<feature-name>

For new features

bugfix/<bug-name>

For bug fixes

hotfix/<issue-name>

For urgent production fixes

release/<version>

For release preparation

Team Collaboration

Working with remotes and managing team workflows.

Remote Operations

git remote -v List all remotes
git remote add <name> <url> Add new remote
git remote remove <name> Remove remote
git remote set-url <name> <url> Change remote URL

Syncing Changes

git fetch --all Fetch all remote branches
git pull origin main Pull from specific branch
git push origin --all Push all branches
git push --tags Push all tags

Conflict Resolution

  1. 1. Identify conflicts: git status
  2. 2. Edit conflicted files
  3. 3. Stage resolved files: git add <file>
  4. 4. Complete merge: git commit
  5. Alternative: Use merge tool: git mergetool

Troubleshooting & Recovery

Solutions to common Git problems and disaster recovery.

Common Issues & Solutions

Accidentally committed wrong file

git reset HEAD <file> Unstage a file

Need to undo last commit

git reset --soft HEAD~1 Undo commit but keep changes

Committed to wrong branch

git checkout <correct-branch> && git cherry-pick <commit-hash> Move commit to correct branch

Merge conflicts

git merge --abort Abort merge and start over

Wrong remote url

git remote set-url origin <correct-url> Update remote URL

Disaster Recovery

git reflog Show recent operations
git reset --hard HEAD@{n} Reset to state n
git checkout - Go to previous branch
git clean -fd Remove untracked files

Best Practices

Industry-standard Git practices for better collaboration.

Commit

  • Write clear, descriptive commit messages
  • Use present tense ("Add feature" not "Added feature")
  • Limit first line to 50 characters
  • Reference issue numbers when applicable
  • Make atomic commits (one logical change per commit)
  • Avoid committing debug code (dd(), console.log)

Branch

  • Keep branches focused and short-lived
  • Use descriptive branch names
  • Delete merged branches regularly
  • Rebase feature branches before merging
  • Never rebase published commits

Workflow

  • Pull before starting work
  • Commit frequently with logical changes
  • Push regularly to backup work
  • Review changes before committing
  • Use .gitignore for generated files
  • Never commit sensitive data (.env, keys)

Team

  • Create Pull Requests for code review
  • Keep PRs focused and small
  • Respond to review feedback promptly
  • Resolve conflicts locally before pushing
  • Use descriptive PR titles and descriptions

Common Workflows

🚀 Feature Development

# Start new feature git checkout -b feature/new-auth-system # Make changes and commit git add . git commit -m "feat: add OAuth2 authentication" # Push to remote git push -u origin feature/new-auth-system # Create Pull Request on GitHub/GitLab # After review and merge, switch back to main git checkout main git pull # Delete feature branch git branch -d feature/new-auth-system

🐛 Bug Fix Workflow

# Create bugfix branch git checkout -b bugfix/login-crash # Fix the bug and test git add . git commit -m "fix: resolve null pointer in login" # Push and create PR git push -u origin bugfix/login-crash # Get it merged, then cleanup git checkout main git pull git branch -d bugfix/login-crash

🔥 Production Hotfix

# Create hotfix from release or main git checkout -b hotfix/critical-security-patch # Make urgent fix git add . git commit -m "hotfix: patch SQL injection vulnerability" # Push and deploy immediately git push -u origin hotfix/critical-security-patch # After deployment, merge back git checkout main git merge hotfix/critical-security-patch git push

🔄 Daily Sync Workflow

# Start of day - sync with main git checkout main git pull origin main # Start working on your branch git checkout feature/my-work git rebase main # Keep your branch up-to-date # End of day - backup your work git push origin feature/my-work