Labs ICT
โญ Pro Login

Git Workflow & Branching

Version control strategies, branching models, and Git best practices.

Git Workflow & Branching

Git is the most widely used version control system. Understanding Git workflows and branching strategies is essential for collaborating effectively and maintaining a clean project history.

Git Basics


  GIT WORKFLOW
  ============

  Working Directory  -->  Staging Area  -->  Local Repo  -->  Remote Repo
       |                    |                  |                |
     git add             git commit         git push        github
     (files)             (snapshot)         (upload)        (server)

  Three States:
  - Modified: Changed but not staged
  - Staged: Marked for next commit
  - Committed: Saved to local repository

Branching Models


  GITFLOW WORKFLOW
  ================

  main (production)
    |
    +-- develop (integration)
    |     |
    |     +-- feature/user-auth
    |     +-- feature/payments
    |     +-- feature/notifications
    |
    +-- release/v1.0
    |
    +-- hotfix/critical-bug

  Branch Types:
  - main:     Production-ready code
  - develop:  Integration branch
  - feature:  New features (branch from develop)
  - release:  Prepare for release
  - hotfix:   Emergency production fixes

Git Commands


  ESSENTIAL GIT COMMANDS
  ======================

  # Create and switch to branch
  git checkout -b feature/new-feature
  git switch -c feature/new-feature

  # Stage changes
  git add filename.js
  git add .              # Stage all changes

  # Commit with message
  git commit -m "Add user authentication"

  # Push to remote
  git push origin feature/new-feature

  # Pull latest changes
  git pull origin develop

  # Merge branch
  git checkout develop
  git merge feature/new-feature

  # View history
  git log --oneline --graph

Best Practices

  • Commit early, commit often โ€” small, focused commits
  • Write clear commit messages (use imperative mood)
  • Never commit directly to main or develop
  • Pull before pushing to avoid conflicts
  • Use .gitignore to exclude build artifacts and secrets

Key Takeaways

  • Git tracks changes through staging, committing, and pushing
  • Branching enables parallel development without conflicts
  • GitFlow provides a structured branching model
  • Good Git habits improve team collaboration

๐Ÿงช Quick Quiz

What is the main purpose of Git?