Git Notes#
This project uses a Gitflow Workflow tailored for a single developer, focusing on maintaining a main branch with feature, release, and hotfix branches.
Gitflow Workflow Overview#
The Gitflow Workflow is ideal for managing complex projects with multiple release stages. Here’s a detailed explanation of how to use this workflow in your project:
Create a Feature Branch: For each new feature, create a new branch off the
development
branch. Use descriptive names likefeature/add-login
.git checkout -b feature/your-feature-name development
Make Commits: Commit your changes in small, logical chunks with clear and descriptive commit messages.
git add . git commit -m "Add user login feature"
Push Feature Branch to Remote: Regularly push your branch to the remote repository to back up your work.
git push origin feature/your-feature-name
Finish Feature Branch: Once your feature is complete, merge it back into the
development
branch.git checkout development git pull origin development git merge feature/your-feature-name git push origin development
Clean Up: After merging, delete the feature branch locally and remotely to keep your branch list clean.
git branch -d feature/your-feature-name git push origin --delete feature/your-feature-name
Create a Release Branch: When you’re ready to prepare a new release, create a release branch from
development
.git checkout -b release/1.0.0 development
Finalize the Release: Finalize your release by merging the release branch into both
main
anddevelopment
, then tag the release.git checkout main git merge release/1.0.0 git tag -a v1.0.0 -m "Release v1.0.0" git push origin main --tags git checkout development git merge release/1.0.0 git push origin development
Clean Up Release Branch: After merging, delete the release branch locally and remotely.
git branch -d release/1.0.0 git push origin --delete release/1.0.0
Create a Hotfix Branch: For urgent fixes on production, create a hotfix branch from
main
.git checkout -b hotfix/1.0.1 main
Apply the Hotfix: Commit your hotfix and merge it back into both
main
anddevelopment
.git add . git commit -m "Fix critical issue" git checkout main git merge hotfix/1.0.1 git tag -a v1.0.1 -m "Hotfix v1.0.1" git push origin main --tags git checkout development git merge hotfix/1.0.1 git push origin development
Clean Up Hotfix Branch: After merging, delete the hotfix branch locally and remotely.
git branch -d hotfix/1.0.1 git push origin --delete hotfix/1.0.1
Commit Message Template#
A good commit message should explain what and why rather than how. Use the following template to structure your commit messages:
Type: Short description of the change (use imperative mood)
Detailed explanation of the change and its context, if necessary. Include references to issues or tickets (e.g., "Closes #123").
Commit Message Examples#
Examples#
Feature Addition:
feat: add user login feature Add a new feature that allows users to log in using their email and password. This includes the login form, validation, and API integration. Closes #45.
Bug Fix:
fix: resolve issue with user session timeout Fix a bug that caused user sessions to timeout prematurely. The session duration is now correctly set to 30 minutes. Closes #67.
Commit Types#
feat: New feature
fix: Bug fix
refactor: Rewrite/restructure code
perf: Performance improvements
style: Non-functional update (white space, formatting, missing semi-colons, …)
test: Test management/correcting
docs: Documentation updates
build: Build components updates (build tool, dependencies, project version, …)
ops: Operational updates (deployment, backup, recovery, …)
chore: Miscellaneous commits (.gitignore, …)
Git Command Tips#
Check Current Branch:
git branch
Create a New Branch:
git checkout -b branch-name
Stage Changes for Commit:
git add .
Commit Changes:
git commit -m "your commit message"
Push Branch to Remote:
git push origin branch-name
Update Local Main Branch:
git checkout main git pull origin main
Merge Branch into Main:
git checkout main git merge branch-name git push origin main
Delete a Branch Locally:
git branch -d branch-name
Delete a Branch Remotely:
git push origin --delete branch-name