Tech

Git-Flow cheat sheet

Git-Flow cheat sheet. Explore our ultimate quick reference for Git-Flow.

This cheat sheet provides essential commands and workflows for using Git-Flow, a branching model designed to streamline development and release processes. It covers repo creation, managing development, features, releases, and hotfixes. Each section includes necessary commands and examples to help you efficiently navigate and implement Git-Flow.

Creating Git Repository

Initialize Repository

  • Create directory:
    mkdir <directory>
    cd <directory>
  • Create bare repo:
    git init --bare
  • Clone repo:
    git clone <repo>
    cd <repo-folder>
  • Create .gitignore file, commit, and push:
    echo "*.log" > .gitignore
    git add .gitignore
    git commit -m "Added .gitignore file"
    git push

Develop Branch

Create Develop Branch

  • Create and push develop branch:
    git branch develop
    git push -u origin develop

Feature Branches

Start Feature

  • Create feature branch from develop:
    git checkout develop
    git checkout -b feature/branch
    git push --set-upstream origin feature/branch

Finish Feature

  • Merge feature branch back into develop:
    git checkout develop
    git merge feature/branch
    git push

Release Branches

Start Release

  • Create release branch from develop:
    git checkout develop
    git checkout -b release/0.1.0

Finish Release

  • Merge release branch back into develop:
    git checkout develop
    git merge release/0.1.0
    git push
  • Merge release branch into master:
    git checkout master
    git merge release/0.1.0
    git push
  • Create a tag from master:
    git checkout master
    git tag v0.1.0
    git push origin v0.1.0
  • Delete feature and release branches:
    git branch -d feature/branch
    git push origin --delete feature/branch
    git branch -d release/0.1.0
    git push origin --delete release/0.1.0

Hotfix Branches

Start Hotfix

  • Create hotfix branch from master:
    git checkout master
    git checkout -b hotfix/branch

Finish Hotfix

  • Merge hotfix branch into master:
    git checkout master
    git merge hotfix/branch
    git push
  • Merge hotfix branch into develop:
    git checkout develop
    git merge hotfix/branch
    git push
  • Delete hotfix branch:
    git branch -d hotfix/branch
    git push origin --delete hotfix/branch
  • Create a tag from master:
    git checkout master
    git tag v0.1.1
    git push origin v0.1.1

Tips and Sources

Useful Tips

  • Regularly pull changes from develop to keep feature branches up-to-date.
  • Use descriptive branch names for features, releases, and hotfixes.
  • Clean up remote branches after merging to keep the repository tidy.