← Back to Chapters

Git Workflow

? Git Workflow

? Quick Overview

A Git workflow is a set of rules and practices that define how developers use Git to manage and collaborate on code. Choosing the right workflow improves productivity, code quality, and team coordination.

? Key Concepts

  • Branches isolate work
  • Pull requests enable review
  • Merging integrates changes
  • Stable branches protect production

? Syntax / Theory

Git workflows define how branches like main, develop, feature, release, and hotfix interact. The workflow determines when and how code moves between these branches.

? Code Example — Feature Branch

? View Code Example
# Create and switch to a new feature branch
git checkout -b feature-login

# Add changes and commit them
git add .
git commit -m "Add login feature"

# Push feature branch to remote
git push origin feature-login

? Live Output / Explanation

The feature branch is created independently from main. Changes remain isolated until reviewed and merged via a pull request, ensuring stability of the main codebase.

? Visual Workflow Overview

? feature → ? develop → ? main

? Use Cases

  • Centralized workflow for small teams
  • Feature branch workflow for parallel development
  • Git Flow for large structured projects
  • Forking workflow for open-source contributions

? Tips & Best Practices

  • Keep main always deployable
  • Use descriptive branch names
  • Review code before merging
  • Delete merged branches

? Try It Yourself

  • Try creating a new branch for a feature and merging it into the main branch.
  • Practice working with a develop branch and merging feature branches back into it.
  • Simulate a Git flow by creating release and hotfix branches and merging them back into master and develop.