如何规范搭建用于客户交付的Git工作流?
Got it, let's put together a Git workflow that perfectly matches your requirements—keeping your core codebase stable in master, maintaining a dedicated branch for this client, and leaving room for future customizations for other clients down the line. Here's a step-by-step breakdown:
1. Core Branch Structure
First, let's formalize the branch setup you're targeting:
masterbranch: This is your stable, production-ready core codebase. It only contains fully tested, universally compatible code that serves as the foundation for all client customizations. No client-specific code ever lands here.- Client-specific branch (e.g.,
client-acme-v0.1): A dedicated branch for your current client. This branch will hold all custom features, tweaks, and configurations tailored exactly to their needs—this is the branch you'll use to deploy to their server. - Feature branches (e.g.,
feature/acme-payment-integration): Short-lived branches for developing individual features/fixes for the client. Once tested and approved, they get merged into the client's dedicated branch (not directly intomasterunless the feature benefits all future clients).
2. Step-by-Step Workflow Implementation
2.1 Set Up the Client Branch
If you're starting from an existing master branch:
# First, make sure you're on the latest stable master git checkout master git pull origin master # Create the dedicated client branch (use a clear name tied to the client and version) git checkout -b client-acme-v0.1
2.2 Daily Development for the Client
For every new feature or bug fix for this client:
- Spin up a feature branch off the client's dedicated branch:
git checkout client-acme-v0.1 git checkout -b feature/acme-custom-checkout - Develop, commit, and push your changes to the feature branch:
git add . git commit -m "Add ACME-specific coupon validation to checkout" git push origin feature/acme-custom-checkout - Once the feature is tested and ready, merge it into the client's branch (use
--no-ffto keep a clear history):git checkout client-acme-v0.1 git merge feature/acme-custom-checkout --no-ff git push origin client-acme-v0.1 # Clean up the feature branch once done git branch -d feature/acme-custom-checkout git push origin --delete feature/acme-custom-checkout
2.3 Delivering to the Client
When you're ready to deploy a working version to their server:
- Double-check that the client branch (
client-acme-v0.1) is fully tested and stable. - Tag the version for easy tracking (this lets you pinpoint exactly what's deployed):
git tag -a v0.1-acme -m "ACME client v0.1: initial production deployment" git push origin v0.1-acme - Deploy directly from this client branch to their server (you can use
git pullon the server, or set up a simple CI/CD pipeline if you want automation).
2.4 Syncing Core Improvements to Client Branches
If you fix a critical bug or add a universal feature to master that the client should receive:
# Switch to the client's branch git checkout client-acme-v0.1 # Merge the latest master changes into it git merge master # Resolve any conflicts, test thoroughly, then push the updated client branch git push origin client-acme-v0.1
2.5 Preparing for Future Clients
When you need to build for a new client later:
- Create a fresh dedicated branch from the latest
master:git checkout master git pull origin master git checkout -b client-bob-v0.1 - Repeat the feature branch workflow for the new client—their customizations stay completely isolated from
masterand other client branches.
3. Best Practices to Keep Things Clean
- Never commit directly to
masteror client branches: Always use feature branches for development to avoid breaking stable code. - Sync client branches with
masterregularly: This ensures clients get core bug fixes and improvements without falling behind. - Stick to clear naming conventions: Branch names like
client-[name]-[version]andfeature/[client-name]-[feature]make it easy to track what's what at a glance. - Tag all deployments: Tags act as a safety net—you can quickly roll back to a working version if something goes wrong on the client's server.
内容的提问来源于stack exchange,提问作者Aurélien.AB
相关产品推荐
相关产品推荐

