First, let’s look at the Git flow diagram:
- The flowchart might seem complex at first glance. We’ll use Sourcetree to help understand the process.
Getting Started (Screenshots show Sourcetree operations, commands show actual execution)
Create a new project log-service
mkdir log-service
cd log-service
git init
Initialize project configuration
- Set up framework selection, project description, etc.
- Replace the following commands with your actual operations:
echo "## log-service" > README.md
git add README.md
git commit -m "init project"
Initialize workflow (git flow init
)
- Both red and green arrows in the image can initialize a workflow
Create a new feature (git flow feature start show-log
)
- We’ll create a feature
show-log
- This is checked out from the
develop
branch
Commit code
- Simulate some operations with the following code:
echo "collect show log" > show.log
git add show.log
git commit -m "add: show log"
Complete the feature (git flow feature finish show-log
)
- After completion:
show-log
branch merges intodevelop
show-log
branch gets deleted
Simulating collaborative development conflicts
- Add click logs with two developers working on
click-log-1
andclick-log-2
git flow feature start click-log-1
git flow feature start click-log-2
git checkout feature/click-log-1
echo "click 1 log" > click.log
git add click.log
git commit -m "add: click log"
git checkout feature/click-log-2
echo " first \n click 2 log" > click.log
git add click.log
git commit -m "add: click log"
- Complete feature operations:
git flow feature finish click-log-1
git flow feature finish click-log-2
- The first operation succeeds normally
- The second operation reports conflicts since both modified
click.log
- The
click-log-2
branch remains after failed merge - The actual
git flow feature finish
process:
git checkout develop
git merge feature/<feature_name>
git branch -d feature/<feature_name>
- Resolve conflicts manually, commit changes, then delete branch:
git branch -d feature/click-log-2
Create a release version (git flow release start v1.0.0
)
- Checked out from
develop
branch
Sourcetree
Sourcetree - If a bug is found during testing:
- Fix directly in
release
branch - Simulate release bug fix:
echo "release v1.0.0" > release.log
git add release.log
git commit -m "fix: release bug"
- Fix directly in
Complete release version (git flow release finish v1.0.0
)
Create a hotfix (git flow hotfix start click-log
)
- Emergency fix for production click log issue
- Checked out from
master
branch - Simulate hotfix:
echo "fix click log" >> click.log
git add click.log
git commit -m "fix: click log"
Complete hotfix (git flow hotfix finish click-log
)
Important Notes
Remote repository connection
- For remote repositories, use
publish
operation afterstart
git flow feature publish <feature_name>
does:- Creates remote
feature/<feature_name>
branch - Sets local branch to track remote
- Pushes uncommitted changes
- Creates remote
To push or not to push
- Push if feature requires collaboration
- No need if working solo
Merging considerations
In team collaboration:
- Repository admin should create
master
branch and initialize GitFlow locally before pushing bothmaster
anddevelop
to remote (with write protection onmaster
) - Collaborators clone project and initialize GitFlow with same configs
- Collaborators push features to
develop
- Admin handles release branches and versioning
References
The Ultimate Guide to Gitflow Usage
Git Flow Workflow Implementation in Sourcetree
https://www.git-tower.com