多设备Drupal网站开发协作工作流优化问题咨询
Optimal Drupal Development Workflow with Self-Hosted GOGS Across Two Devices
Hey there! As someone who’s juggled Drupal development across multiple machines with private repos, I’ve got a solid workflow to share that’ll keep your work consistent, secure, and hassle-free. Let’s dive in:
1. First: Lock Down Your GOGS & Git Setup
Before diving into daily work, make sure both devices are properly configured to interact with your GOGS repo:
- SSH Keys for Passwordless Access: Generate an SSH key on each device with
ssh-keygen -t ed25519 -C "your-email@example.com", then add the public key (~/.ssh/id_ed25519.pub) to your GOGS account settings. This eliminates typing passwords every time you push/pull. - Project Gitignore: Create a
.gitignorefile in your Drupal root and add these critical entries to avoid syncing local-only files:
Note: Keepsites/default/files/ sites/default/settings.local.php vendor/ *.sql .envcomposer.lockin Git—this ensures both devices install identical dependency versions.
2. Daily Development Workflow (Cross-Device Friendly)
The key here is to avoid working directly on your main branch and use feature branches for all changes. Here’s how to bounce between laptop and desktop smoothly:
Scenario 1: Starting Work on One Device
- Pull the latest stable code from GOGS:
git pull origin main - Create a dedicated feature branch:
git checkout -b feature/add-contact-form-validation - Code away! Commit frequently with clear messages:
git commit -m "Add server-side validation for contact form fields" - Push the branch to GOGS when you’re ready to switch devices:
git push origin feature/add-contact-form-validation
Scenario 2: Switching to the Other Device
- Fetch all remote branches:
git fetch origin - Check out your feature branch:
git checkout feature/add-contact-form-validation - Pull any new commits you pushed earlier:
git pull origin feature/add-contact-form-validation - Resume coding—no lost work, no messy conflicts (yet!)
Handling WIP (Work in Progress) Code
If you need to switch mid-task without finishing a commit:
- Stash your changes temporarily:
git stash push -m "WIP: Half-finished AJAX submission logic" - On the other device, retrieve the stash:
git stash apply - Alternatively, commit a WIP change:
git commit -m "WIP: Start AJAX submission work"—push it to GOGS, then on the other device, usegit reset HEAD~1to undo the commit and return to your uncommitted state. This is safer than stashes if you’re worried about losing work.
3. Drupal-Specific Optimizations
Drupal has unique quirks—here’s how to keep your local environments in sync:
- Local Configuration Separation: Each device should have its own
settings.local.php(ignored by Git) with database credentials, debug mode settings, and local caching configs. Add this line to your mainsettings.phpto load the local file automatically:if (file_exists(__DIR__ . '/settings.local.php')) { include __DIR__ . '/settings.local.php'; } - Database Sync: When you need to move your Drupal database between devices:
- On the source device, dump the DB with Drush:
drush sql-dump --result-file=drupal-db.sql - Transfer the
.sqlfile to the target device (use scp, a USB drive, or a private file sync tool—avoid committing large SQL files to Git!) - On the target device, import with Drush:
drush sql-drop && drush sql-cli < drupal-db.sql - For a faster workflow, set up Drush site aliases so you can run
drush sql-sync @laptop @desktopdirectly (if devices can reach each other over your network).
- On the source device, dump the DB with Drush:
- Composer Dependency Consistency: Always run
composer install(notcomposer update) on both devices to install exact versions fromcomposer.lock. If you need to update dependencies, do it on one device, commit the updatedcomposer.lock, then pull and runcomposer installon the other.
4. Branch & Repo Maintenance
- Keep your
mainbranch stable: Only merge feature branches intomainafter testing them thoroughly on one device first. - Use GOGS Pull Requests (if available): Even though you’re working alone, PRs let you review your own code, leave notes, and keep a clean commit history. Merge the PR to
mainonce you’re satisfied. - Clean up old branches: Once a feature is merged, delete the branch locally (
git branch -d feature/old-branch) and remotely (git push origin --delete feature/old-branch) to keep your repo tidy.
5. Troubleshooting Common Issues
- Merge Conflicts: If you accidentally work on the same file across devices, use
git diffto see the conflict, resolve it manually, then commit the fix. For Drupal config files (inconfig/sync), double-check that you’re not overriding active config changes. - Dependency Mismatches: If one device has missing packages, delete the
vendorfolder, rungit checkout composer.lock, thencomposer installto reset dependencies. - GOGS Sync Errors: If pushes/pulls fail, verify your SSH key is still active in GOGS, and that your device has network access to the VPS hosting GOGS.
内容的提问来源于stack exchange,提问作者woxene
相关产品推荐
相关产品推荐

