When I start working on a new automation script that will eventually be used by other engineers on my team, I follow a structured Git workflow to ensure collaboration, code quality, and ease of onboarding for others. Here's a step-by-step breakdown:
1. Create a New Branch
I start by creating a new feature branch from the main or default branch (e.g., main or develop), using a clear and descriptive name:
bash
git checkout -b feature/new-automation-script
This isolates my work and ensures the main branch remains stable.
2. Set Up the Project Structure
Even for a small script, I create a clean structure that will make it easy for others to understand and use later. This often includes:
script_name.py or script_name.sh (depending on the language)
README.md – explaining the purpose, usage, and dependencies
.gitignore – to exclude any unnecessary files
requirements.txt or similar, if applicable
I commit early and often, with clear, atomic commits:
bash
git add .
git commit -m "Initial commit: Set up project structure and basic README"
3. Develop Iteratively with Meaningful Commits
As I build out the automation logic, I follow these practices:
Write modular, readable, and well-documented code
Add comments and logging where appropriate
Use version control to track changes and experiment safely
Commit small, logical changes with descriptive commit messages:
bash
git commit -m "Add core functionality for data validation"
Use .gitignore to exclude logs, environment files, or secrets
4. Test Locally and Add Unit Tests (if applicable)
I test the script thoroughly to ensure it behaves as expected in different scenarios. If it's a more complex script, I include unit or integration tests. I also test it in the environments it's expected to run in (e.g., Linux, macOS, CI/CD).
I commit the tests and any test fixtures:
bash
git commit -m "Add unit tests for validation logic"
5. Push to Remote and Open a Draft Pull Request (PR)
Once the script is functional and well-documented, I push my branch to the remote repository:
bash
git push origin feature/new-automation-script
Then, I open a draft PR on the platform (e.g., GitHub, GitLab). This signals to the team that the script is in progress but not yet ready for review.
6. Request Feedback and Iterate
I convert the PR to "Ready for review" when the script is complete and includes:
Clear documentation
Examples of usage
Any necessary configuration or setup steps
Test results or logs
I request feedback from at least one team member, especially those who may be using or maintaining the script later.
7. Address Review Comments
I address any feedback or suggestions by making changes in the same branch. Each fix is committed with a clear message:
bash
git commit -m "Fix edge case handling in input validation"
I push updates and keep the PR conversation active until all concerns are resolved.
8. Merge into Main Branch
Once the PR is approved and any required CI/CD checks pass, I merge the branch into the main branch using a merge commit or squash merge, depending on the team’s preference:
bash
git checkout main
git pull origin main
git merge --no-ff feature/new-automation-script
git push origin main
Or via the Git platform UI.
9. Notify the Team
After merging, I notify the team—often via Slack, email, or a project management tool—about the new automation script, where to find it, and how to use it.
10. (Optional) Create a Release or Tag (if applicable)
If we use semantic versioning or release cycles, I might tag the commit for easier reference:
bash
git tag -a v1.0.0 -m "Release version 1.0.0 of new automation script"
git push origin v1.0.0
Summary of the Git Workflow
Branch off main
Build and commit iteratively
Push and open draft PR
Get feedback and refine
Merge after approval
Notify and document usage
This workflow ensures the automation script is robust, well-documented, and easy for others to adopt and extend.