Skip to content

Instantly share code, notes, and snippets.

@khilnani
Created March 5, 2018 06:52
Show Gist options
  • Save khilnani/8f47937066d5a7c8cfe96fefff566662 to your computer and use it in GitHub Desktop.
Save khilnani/8f47937066d5a7c8cfe96fefff566662 to your computer and use it in GitHub Desktop.

Git Feature Branching

See Git Featrue Branch workflow

Create a Branch

  • Checkout develop:

    • git checkout develop
    • git pull origin develop
  • Create a branch:

    • git checkout -b branches/branch-name
  • Do work:

    • git commit -m "Comment about the commit"
  • Rebase frequently to incorporate upstream changes:

    • git fetch origin develop
    • git rebase origin/develop
    • or -
    • git checkout develop
    • git pull
    • git checkout branches/branch-name
    • git rebase develop
  • Optional: Perform an interactive rebase (squash) your commits before pushing the branch:

    • git fetch origin develop
    • git rebase -i origin/develop
  • Review and validate, push your changes upstream to origin:

    • git push -u origin branches/branch-name

Merge to Develop

  • git checkout develop
  • git pull
  • git pull origin branches/branch-name
  • git push

Merge to Master

  • git checkout master

  • git pull

  • git pull origin develop git push

  • Delete the Feature branch

    • Local: git branch -d branches/branch-name
    • Remote: git push origin --delete branches/branch-name

Hotfix

  • Pull to update your local master branch:

    • git checkout master
    • git pull origin master
  • Check out a hotfix branch.

    • git checkout -b hotfix-branch-name
  • Do work in your hotfix branch, committing early and often:

    • git commit -m "Comment about the commit"
  • Interactive rebase (squash) your commits:

    • git fetch origin master
    • git rebase -i origin/master
  • Push your changes upstream, get code reviewed

    • git push -u origin hotfix-branch-name
  • Merge your changes with master

    • git checkout master
    • git merge --no-ff hotfix-branch-name
  • Back-merge your changes with development

    • git checkout develop
    • git merge --no-ff hotfix-branch-name
  • Push your changes upstream

    • git push origin master
    • git push origin develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment