-
Initialize a new Git repository:
bashCopy code mkdir myproject cd myproject git init -
Commit an initial empty commit (this helps in setting up the base for branching):
bashCopy code git commit --allow-empty -m "Initial commit" -
Create the
developbranch and switch to it:bashCopy code git checkout -b develop
Now you have both master and develop branches, with develop being the one you'll work on.
-
Create a new feature branch:
bashCopy code git checkout -b feature/new-awesome-feature develop
-
Make changes for the feature and commit them:
bashCopy code echo "This is my new feature" > feature.txt git add feature.txt git commit -m "Add new awesome feature"
-
Once the feature is complete, merge it into the
developbranch:bashCopy code git checkout develop git merge --no-ff feature/new-awesome-feature git branch -d feature/new-awesome-feature
-
Create a release branch:
bashCopy code git checkout -b release/1.0.0 develop
-
Make any final adjustments needed for the release (like bumping version numbers, updating documentation, etc.) and commit those changes.
-
Once the release is ready, merge it into
masterand tag it:bashCopy code git checkout master git merge --no-ff release/1.0.0 git tag -a 1.0.0
-
Also, merge the changes back into
develop:bashCopy code git checkout develop git merge --no-ff release/1.0.0
-
Delete the release branch:
bashCopy code git branch -d release/1.0.0
-
Create a hotfix branch from
master:bashCopy code git checkout -b hotfix/1.0.1 master
-
Make and commit the hotfix changes:
bashCopy code echo "Hotfix applied" > hotfix.txt git add hotfix.txt git commit -m "Fix critical issue"
-
Merge the hotfix branch into both
masteranddevelop:bashCopy code git checkout master git merge --no-ff hotfix/1.0.1 git tag -a 1.0.1 git checkout develop git merge --no-ff hotfix/1.0.1
-
Delete the hotfix branch:
bashCopy code git branch -d hotfix/1.0.1
Throughout the GitFlow process, you've been merging changes back to the main branches (master and develop) at the end of each feature, release, or hotfix. This ensures that:
- The
masterbranch always reflects the production-ready state. - The
developbranch always contains the latest delivered and approved features.
By consistently merging back, you ensure that both branches are up-to-date and that features, fixes, and releases are systematically integrated into your project's main lines of development.