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:
- Create an appropriate work item for your assigned activity.
- 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}.
- 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}
- Continue your work in that branch.
- Post completion, commit your branch local. $ git commit -m âyour commit messageâ.
- Rebase the feature branch onto the âdevâ branch. $ git rebase .
- 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...đ