|
| 1 | +--- |
| 2 | +title: Git Working Rules |
| 3 | +tags: [git] |
| 4 | +description: My personal Git cheat sheet |
| 5 | +image: https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Git-logo.svg/1024px-Git-logo.svg.png |
| 6 | +--- |
| 7 | + |
| 8 | +### 👥 Roles |
| 9 | + |
| 10 | +* **Repository Owner** |
| 11 | + |
| 12 | + * Manage repo access |
| 13 | + * Prevent direct commits to `develop`, `test`, `uat`, `prod` |
| 14 | + * Review merge important branches: `test`, `uat`, `prod` |
| 15 | + |
| 16 | +* **Maintainers (Lead Devs)** |
| 17 | + |
| 18 | + * Manage `release` & `hotfix` branches |
| 19 | + * Review & merge pull requests (PRs) |
| 20 | + * Help define working process |
| 21 | + |
| 22 | +* **Developers** |
| 23 | + |
| 24 | + * Create `feature/*`, `bugfix/*`, or `hotfix/*` branches from `develop` |
| 25 | + * Submit PRs to `develop` when done. |
| 26 | + * Include detailed description in PRs. |
| 27 | + * Review and improve PRs. |
| 28 | + |
| 29 | +* **DevOps** |
| 30 | + |
| 31 | + * Manage deployments and system config |
| 32 | + * Deploy code from `develop`, `test`, `uat`, `prod` |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +### 🔁 Git Flow |
| 37 | + |
| 38 | +> Dev is the default branch. All development starts from here. |
| 39 | +
|
| 40 | +1. **`develop`** – Active development (default branch) |
| 41 | + |
| 42 | + * All new work branches are created from here |
| 43 | + * Only `develop` can merge into `test` |
| 44 | + |
| 45 | +2. **`test`** – Internal QA/testing |
| 46 | + |
| 47 | + * Only receives merges from `develop` |
| 48 | + * Can merge into `uat` |
| 49 | + |
| 50 | +3. **`uat`** – Pre-release, client/user testing |
| 51 | + |
| 52 | + * Only receives merges from `test` |
| 53 | + * Can merge into `prod` |
| 54 | + |
| 55 | +4. **`prod`** – Final, stable version |
| 56 | + |
| 57 | + * Only receives merges from `uat` |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +### 🪴 Branching Rules |
| 62 | + |
| 63 | +* You **must use one of the following prefixes** for branches: |
| 64 | + |
| 65 | + * `feature/*` – For new features or enhancements |
| 66 | + * `bugfix/*` – For fixing bugs found during development |
| 67 | + * `hotfix/*` – For urgent, production-critical fixes |
| 68 | +* All branches must be created from `develop` |
| 69 | +* Example: `feature/user-login`, `bugfix/payment-crash`, `hotfix/api-down` |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +### ✍️ Committing |
| 74 | + |
| 75 | +* Write **clear, meaningful** commit messages |
| 76 | +* Avoid **unrelated changes** in a single commit |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +### 🔀 Merging |
| 81 | + |
| 82 | +* All changes go through **Merge Requests (MRs)** |
| 83 | +* MRs must be **code reviewed** |
| 84 | +* **Use rebase on feature branches** to keep history clean |
| 85 | +* **Use merge into `develop` and above** to retain full collaboration history |
| 86 | +* Merge paths must follow environment flow: |
| 87 | + |
| 88 | + * `develop` → `test` → `uat` → `prod` |
| 89 | +* Auto-merge only if tests pass (future feature) |
| 90 | +* Delete merged branches (except protected ones) |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +### 🏷️ Versioning & Clean Code |
| 95 | + |
| 96 | +* Use **tags** for releases |
| 97 | +* Use `.gitignore` for non-tracked files (e.g. `.env`) |
| 98 | +* Never commit **sensitive info** (keys, tokens) |
| 99 | +* Document environment variables in `README` |
| 100 | +* No **absolute paths** in code (e.g. `/home/user/...`) |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +### 💡 Best Practices |
| 105 | + |
| 106 | +* **CI/CD**: Auto-test & build on commit |
| 107 | +* **Conflict resolution**: Resolve before merge |
| 108 | +* **Repo size**: Keep small (limit: 5–20MB) |
| 109 | +* **Code conventions**: Follow team style guides |
| 110 | +* **Code reviews**: Review before merging |
| 111 | +* **Documentation**: Keep everything documented |
| 112 | +* **Backup**: Regularly back up repo |
| 113 | +* **Hooks**: Use Git hooks to validate code before commit |
| 114 | +* **Cleanup**: Remove unused branches regularly |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +### 📘 References |
| 119 | + |
| 120 | +* [Atlassian Git Flow Guide](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) |
| 121 | +* [Git Cheat Sheet (GitHub)](https://education.github.com/git-cheat-sheet-education.pdf) |
| 122 | +* [Learn Git Branching (interactive)](https://learngitbranching.js.org/) |
| 123 | +* [Pro Git Book](https://git-scm.com/book/en/v2) |
0 commit comments