A tutorial introduction to branches 🌲

A tutorial introduction to branches 🌲

Basic Branching and Merging

Let’s go through a simple example of branching and merging with a workflow that you might use in the real world. You’ll follow these steps:

Check out a Repository

$ git clone

Description: Clones a repository into a newly-created directory, creates remote-tracking branches for each branch in the cloned repository (visible using git branch -r) and creates and checks out an initial branch that is forked from the cloned repository’s active branch.

After the clone, a plain ‘$ git fetch’ without arguments will update all the remote-tracking branches, and a ‘$ git pull’ without arguments will, in addition, merge the remote master branch into the current master branch.

The feature branch should always checkout from branch ‘dev’ and not from ‘master’. So post successful remote clone setup ‘$ git checkout dev’ checks out an initial ‘dev’ branch that is forked from the cloned repo.

A. Steps in creating a Feature branch:

  1. Create an appropriate work item for your assigned activity.
  2. Create a branch using short and descriptive names for the new work item logged. Use hyphens to separate your descriptive names and use task id as an optional one. Eg: $ git checkout -b {your-feature}.
  3. A feature shared among multiple persons might have a personal feature branch and team-wide feature branch. $ git checkout -b {your-feature}/master ; $ git checkout -b {your-feature}/{name of person}
  4. Continue your work in that branch.
  5. Post completion, commit your branch local. $ git commit -m “your commit message”.
  6. Rebase the feature branch onto the ‘dev’ branch. $ git rebase .
  7. Push your feature branch to upstream. $ git push origin

B. Feature branch Release:

Checkout to ‘dev’ branch and pull the latest. Merge your feature branch to dev. $ git merge --no--ff . Ensure that your project source files compile correctly before running the linter. Post successful syntactic & semantic checks, release your build. Use tag operation to push your release build version. $ git tag ; $ git tag -a “{your description}” ; $ git push origin

C. Feature branch bugfix/change request/hotfix. You’ll do the following:

Create a branch using the following format {bug/CR/hotfix}-{short summary}-{optional id}. Follow steps (3,4,5,6) from section A. Follow steps (1 to 4) from section B.

Do commit early and often...😆

Â