4.3 KiB
Contributing Guide
Development Guidelines
Code Quality Tools
-
Pre-commit setup:
pre-commit install
-
Configured hooks:
- YAML checking
- End-of-file fixer
- Trailing whitespace removal
- Ruff (linting + formatting)
- MyPy (type checking)
Coding Standards
- Follow PEP 8 guidelines.
- Use type hints consistently.
- Maximum line length: 130 characters.
- Use single quotes for strings.
Commit Guidelines
Use Commitizen for standardized commits:
git cz
Git Strategy: Feature branch
The Git Feature Branch Workflow is a way to work on new features in a project without messing up the main code. Instead of working directly on the main
branch (the "official" code), you create a separate branch for each feature. This keeps the main
branch clean and stable.
How It Works (Diagram)
Example:
git branch -d add-login-button
git push origin --delete add-login-button
Example Workflow (Diagram)
Here’s an example of how Mary uses this workflow:
sequenceDiagram
participant Mary
participant GitHub
participant Bill
Mary->>GitHub: Create a new branch (add-login-button)
Mary->>Mary: Make changes and commit
Mary->>GitHub: Push branch to remote
Mary->>GitHub: Open a pull request
Bill->>GitHub: Review pull request
Bill->>Mary: Request changes
Mary->>Mary: Fix feedback and commit
Mary->>GitHub: Push updates
Bill->>GitHub: Approve pull request
Mary->>GitHub: Merge branch into main
Mary->>GitHub: Delete feature branch
General Step-by-Step Instructions
1. Start with the main branch
Make sure your local main branch is up-to-date with the latest code from the central repository.
git checkout main
git fetch origin
git reset --hard origin/main
2. Create a new branch for your feature
Create a branch for your feature. Use a clear name that describes what you’re working on, like add-login-button
or fix-bug-123
.
git checkout -b your-branch-name
Example:
git checkout -b add-login-button
3. Work on your feature
Make changes to the code. After making changes, save your work by following these steps:
-
Check what files you’ve changed:
git status
-
Add the files you want to save:
git add <file-name>
Example:
git add index.html
-
Save your changes with a message:
git commit -m "Describe what you changed"
Example:
git commit -m "Added login button to homepage"
4. Push your branch to the remote repository
To back up your work and share it with others, push your branch to the central repository.
git push -u origin your-branch-name
Example:
git push -u origin add-login-button
5. Open a pull request
Go to your Git hosting platform (like GitLab) and open a pull request. This is how you ask your team to review your changes and approve them before adding them to the main branch.
6. Fix feedback from reviewers
If your teammates suggest changes, follow these steps to update your branch:
- Make the changes locally.
- Save the changes:
git add <file-name> git commit -m "Fixed feedback" git push
7. Merge your branch into main
Once your pull request is approved, it’s time to merge your branch into the main branch.
-
Switch to the main branch:
git checkout main
-
Update your local main branch:
git pull
-
Merge your feature branch into main:
git merge your-branch-name
-
Push the updated main branch to the remote repository:
git push
8. Delete your feature branch
After merging, delete your feature branch to keep things clean.
-
Delete the branch locally:
git branch -d your-branch-name
-
Delete the branch from the remote repository:
git push origin --delete your-branch-name
Summary
- Create a branch for each feature.
- Work on your branch without touching
main
. - Push your branch to back up your work.
- Open a pull request to get feedback and approval.
- Merge your branch into
main
when it’s ready. - Delete your branch after merging.
By following these steps, you’ll keep the main
branch clean and make it easy for your team to collaborate.