Skip to content

Instantly share code, notes, and snippets.

@tuladhasum
Last active June 8, 2019 08:38
Show Gist options
  • Select an option

  • Save tuladhasum/c39249782a384d36ceac0c9946538b09 to your computer and use it in GitHub Desktop.

Select an option

Save tuladhasum/c39249782a384d36ceac0c9946538b09 to your computer and use it in GitHub Desktop.
Git Branching

Git Branching

Feature branch

Creating a feature branch

May branch off from: develop

Must merge back into: develop

Branch naming convention: anything except master, develop, release-*, or hotfix-*

When starting work on a new feature, branch off from the develop branch.

$ git checkout -b myfeature develop
# Switch to a new branch "myfeature"

Incorporating a finished feature on develop

Finished features may be merged into the develop branch to definitely add them to the upcoming release

$ git checkout develop
# Switched to branch 'develop'. Always checkout the branch you want to merge into 

$ git merge --no-ff myfeature
# Use --no-ff flag causes the merge to always create a new commit

$ git branch -d myfeature
# Delete the merged branch

$ git push origin develop
# Push back the origin to the develop branch to remote

Release Branch

May branch off from: develop

Must merge back into: develop and master

Branch naming convention: release-*

Creating a release branch

$ git checkout -b release-1.2 develop
# Switched to a new branch "release-1.2"

$ ./bump-version.sh 1.2
# Change all the version number in the application

$ git commit -am "Bumped version number to 1.2"

Finishing a release branch

$ git checkout master
# Switch to branch master. The branch you want to merge to

$ git merge --no-ff release-1.2

$ git tag -a 1.2

To keep the changes made in the release branch, we need to merge those back into develop, though.

$ git checkout develop

$ git merge --no-ff release-1.2

$ git branch -d release-1.2
# Delete the release branch

Hotfix Branch

May branch off from: master

Must merge back into: develop and master

Branch naming convention: hotfix-*

Creating the hotfix branch

$ git checkout -b hotfix-1.2.1 master
# create a new branch from the master

$ ./bump-version.sh 1.2.1

$ git commit -am "Did the hot Fix 1.2.1"

Finishing a hotfix branch

When finished, the bugfix needs to be merged back into master, but also needs to be merged back into develop

$ git checkout master
# Switch to master branch

$ git merge --no-ff hotfix-1.2.1
# Merge it back to the master

$ git tag -a 1.2.1

Include the bugfix in develop too

$ git checkout develop
# Switch to develop branch

$ git merge --no-ff hotfix-1.2.1
# Merge the hotfix to develop

$ git branch -d hotfix-1.2.1
# Delete the hotfix branch

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment