This repository demonstrates best practices for using Git, particularly focusing on small, focused commits and managing branches effectively. The project is a simple TypeScript-based calculator application with unit tests written using Jest.
for the documentation this repo was created for: https://gist.github.com/thatkookooguy/e8b2e32abe9818b14246fc3bb4686147
To get started with this project, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/git-best-practices-calculator-app.git cd git-best-practices-calculator-app -
Install dependencies:
npm install
-
Build the project:
npm run build
-
Run the project:
npm start
-
Run tests:
npm test -
Run tests in watch mode:
npm run test:watch
This repository includes several branches, each demonstrating different aspects of Git best practices. Below is a brief explanation of each branch:
-
main
- The main branch contains the completed calculator app with all features implemented and tested.
-
base-branch
- The base branch serves as the starting point for all feature branches. It includes the initial setup with TypeScript and Jest.
-
example01/before-unwanted-commit-or-temporary-commit
- This branch shows a feature implemented with several intermediate commits that include temporary or unwanted changes. It demonstrates how not to structure commits.
-
example01/after-unwanted-commit-or-temporary-commit
- This branch is a continuation from
example01/before-unwanted-commit-or-temporary-commitshowing how to move forward after unwanted commits.
- This branch is a continuation from
-
option1/feature/JIRA-001-JIRA-002-implement-calculator
- This branch demonstrates how to correctly split a feature into small, manageable commits. Each commit is focused and represents a logical step in the development process.
-
option1/feature/JIRA-003-JIRA-004-implement-calculator
- Similar to
option1/feature/JIRA-001-JIRA-002-implement-calculator, this branch also shows a feature split into small commits.
- Similar to
-
option2/feature/calculator-implementation
- This branch demonstrates how to split a feature into small commits, starting with empty wrappers for new files and
test.todoplaceholders.
- This branch demonstrates how to split a feature into small commits, starting with empty wrappers for new files and
-
option2/feature/tests-for-calculator-no-bug
- This branch contains the tests for the calculator implementation, showing a clean and structured approach to adding tests.
-
feature/with-bug-showing-git-bisect
- This branch contains a bug introduced in one of the commits. It serves as an example for using
git bisectto identify and fix the bug.
- This branch contains a bug introduced in one of the commits. It serves as an example for using
-
Small, Focused Commits:
- Each commit introduces a small, isolated change, making it easier to review and understand.
- Commits include relevant unit tests to ensure the code is functional and verifiable.
-
Using
test.todo:- Plan tests in advance using
test.todoto outline the test cases and ensure complete test coverage.
- Plan tests in advance using
-
Commit Empty Wrappers:
- Start with empty wrappers for new files and basic test descriptions. This approach makes it easier to cherry-pick commits and reorder changes as needed.
-
Interactive Rebase and Cherry-Pick:
- Use interactive rebase (
git rebase -i) and cherry-pick (git cherry-pick) to manage and refine the commit history effectively.
- Use interactive rebase (
-
Commit Empty Wrappers Separately:
- Committing empty wrappers for new files as a separate commit establishes a clear structure for the codebase. This simplifies the process of cherry-picking and reordering commits.
-
Use
test.todo:test.todohelps outline planned tests, ensuring a comprehensive testing strategy and making it clear what tests need to be implemented.
-
Pair Method Implementation and Tests:
- Pairing method implementation with its corresponding test in the same commit ensures each commit is functional and verifiable. This practice promotes a test-driven development (TDD) approach.
-
Why Keep Commits Small:
- Small, focused commits make it easier to identify and fix bugs, understand the purpose of each change, and facilitate better collaboration and code reviews.
By following these best practices, developers can maintain a clean, organized, and understandable commit history, making it easier to collaborate, review code, and debug issues.
This project is licensed under the MIT License. See the LICENSE file for details. Feel free to customize the content to better fit your specific needs or repository structure.