Popular GIT Workflows

Popular Git Workflows

Git Workflows

Introduction

Different teams use different workflows. This lesson covers the most popular Git workflows and when to use each.

Feature Branch Workflow

Each feature on its own branch.

main:     A---B---C---D
               \
feature:     E---F

How It Works

1. Create branch from main 2. Work on feature 3. Create pull request 4. Review and merge 5. Delete feature branch

Commands

# Start feature
git checkout main
git pull
git checkout -b feature-new-feature

Work and commit

git add . git commit -m "Add feature"

Push and create PR

git push -u origin feature-new-feature

After PR merge

git checkout main git pull git branch -d feature-new-feature

Pros

  • Simple to understand
  • Good for small teams
  • Features isolated

Cons

  • Can cause integration issues
  • No formal review process (without PR)

Gitflow Workflow

More structured with specific branch types.

Branch Types

  • main - Production code
  • develop - Integration branch
  • feature/* - New features
  • release/* - Release preparation
  • hotfix/* - Emergency fixes
main:     A---B---C---D---E
                \       \
develop:     F---G---H---I---J
                  |   |
feature:       K---L   |
                    release: M---N

Commands

# Start feature
git checkout develop
git checkout -b feature-new-feature

Finish feature

git checkout develop git merge feature-new-feature git branch -d feature-new-feature

Start release

git checkout develop git checkout -b release-1.0

Finish release

git checkout main git merge release-1.0 git checkout develop git merge release-1.0 git branch -d release-1.0

Start hotfix

git checkout main git checkout -b hotfix-fix-bug

Finish hotfix

git checkout main git merge hotfix-fix-bug git checkout develop git merge hotfix-fix-bug git branch -d hotfix-fix-bug

Pros

  • Clear structure
  • Good for releases
  • Organized

Cons

  • Complex
  • Many branches

GitHub Flow

Simpler, GitHub-centric workflow.

Rules

1. Branch from main 2. Work on branch 3. Open Pull Request 4. Review and discuss 5. Deploy and test 6. Merge to main

Commands

# Create branch
git checkout main
git pull
git checkout -b feature-name

Work, commit, push

git add . git commit -m "Description" git push -u origin feature-name

Create PR (via GitHub)

After approval and deploy

git checkout main git pull git branch -d feature-name

Pros

  • Simple
  • Continuous delivery
  • GitHub integrated

Cons

  • Requires good tests
  • Deploy-first mindset

Trunk-Based Development

Developers work in main or short-lived branches.

Principles

  • Branches live less than 2 days
  • Small, frequent commits
  • Feature flags for incomplete features
main: A---B---C---D---E---F---G
         \     \     \
feature1  H---I---J   \
                      \
feature2              K---L

Commands

# Very short branch
git checkout main
git pull
git checkout -b feature-small

Quick work

git add . git commit -m "Quick feature"

Back to main quickly

git checkout main git merge feature-small

Pros

  • Fast integration
  • Reduces merge hell
  • Continuous integration

Cons

  • Requires strong testing
  • Feature flags required

Forking Workflow

Contribute without direct repository access.

original-repo/main: A---B---C

fork-repo/main: A---B---C---D

fork-repo/feature: \ E---F

How It Works

1. Fork repository on GitHub 2. Clone your fork 3. Create branch on your fork 4. Make changes and push 5. Create Pull Request to original

Commands

# Clone your fork
git clone https://github.com/you/repo.git
cd repo

Add upstream

git remote add upstream https://github.com/original/repo.git

Create branch

git checkout -b feature

Make changes

git add . git commit -m "Add feature"

Push to your fork

git push origin feature

Create PR to original repo

Pros

  • Open source friendly
  • No permissions needed
  • Clean contributor workflow

Cons

  • More complex
  • Synchronization challenges

Choosing a Workflow

WorkflowTeam SizeRelease CycleComplexity
Feature Branch1-10AnyLow
Gitflow5-20+Scheduled releasesHigh
GitHub Flow2-50ContinuousLow
Trunk-Based10+ContinuousMedium
ForkingAnyAnyMedium

Summary

Choose workflow based on:

  • Team size
  • Release frequency
  • Project complexity
  • Tooling (GitHub, GitLab, etc.)
Start simple and evolve as needed.

Next Lesson

Learn about Git hooks and plugins to extend functionality.

Quiz - Quiz - Popular Git Workflows

1. In Gitflow, which branch contains production code?

2. What is the main characteristic of Trunk-Based Development?

3. Which workflow is most common for open source contributions?

4. In GitHub Flow, when should you create a Pull Request?

5. What is a fork in GitHub?

Stashing Changes