my-notes

Git_Flow

1 min read

Git Flow

Structured workflow for scheduled releases.


πŸ“Š Branch Structure

gitGraph
    commit id: "init"
    branch develop
    checkout develop
    commit id: "dev work"
    branch feature/login
    commit id: "add login"
    checkout develop
    merge feature/login
    branch release/1.0
    commit id: "bump version"
    checkout main
    merge release/1.0 tag: "v1.0"
    checkout develop
    merge release/1.0

πŸ“‹ Branch Types

Branch Purpose Branches from Merges to
main Production - -
develop Integration main -
feature/* New features develop develop
release/* Release prep develop main, develop
hotfix/* Production fixes main main, develop

πŸš€ Feature Branch

Start Feature

git checkout develop

Switch to develop.

git pull origin develop

Get latest.

git checkout -b feature/user-login

Create feature branch.


Work on Feature

git add .

Stage changes.

git commit -m "feat: add login form"

Commit work.


Finish Feature

git checkout develop

Switch to develop.

git merge --no-ff feature/user-login

Merge with merge commit.

git branch -d feature/user-login

Delete feature branch.

git push origin develop

Push develop.


πŸ“¦ Release Branch

Start Release

git checkout develop

Switch to develop.

git checkout -b release/1.0.0

Create release branch.


Prepare Release

git commit -m "Bump version to 1.0.0"

Update version numbers.


Finish Release

git checkout main

Switch to main.

git merge --no-ff release/1.0.0

Merge to main.

git tag -a v1.0.0 -m "Release 1.0.0"

Tag the release.

git checkout develop

Switch to develop.

git merge --no-ff release/1.0.0

Merge back to develop.

git branch -d release/1.0.0

Delete release branch.


Push Everything

git push origin main

Push main.

git push origin develop

Push develop.

git push origin --tags

Push tags.


πŸ”₯ Hotfix Branch

Start Hotfix

git checkout main

Switch to main.

git checkout -b hotfix/1.0.1

Create hotfix branch.


Fix and Commit

git commit -m "fix: critical security bug"

Fix the issue.


Finish Hotfix

git checkout main

Switch to main.

git merge --no-ff hotfix/1.0.1

Merge to main.

git tag -a v1.0.1 -m "Hotfix 1.0.1"

Tag the hotfix.

git checkout develop

Switch to develop.

git merge --no-ff hotfix/1.0.1

Merge to develop.

git branch -d hotfix/1.0.1

Delete hotfix branch.


πŸ’‘ Tips

Use git-flow Extension
brew install git-flow
git flow init
git flow feature start user-login
git flow feature finish user-login
When to Use Git Flow
  • Scheduled releases
  • Multiple versions in production
  • Larger teams


#git #gitflow #workflow #release

Built with mdgarden