
- This feature is provided in git, so that developers can create code related to different functionalities on separate branches.
- This helps the development team in creating the code in an uncluttered way. Later this code can be merged with the master branch.
- Master is final developed code that can move to testing , beta and production servers.
- Simple project structure of Git types of branches : Feature branches, Develop, Release branches, Hotfixes, Master
- Here we can see , programmers develop project features at feature branches, if feature initial unit testing done, result is perfect than he merge that branch with Develop branch, next release , next hotfixes (production code bug fix), next to master → testing server → beta server → Production server.
- By default branch in git is master
- By Default branch in github is main
1 | Creating new branch | git branch <branch-name> | Ex: git branch feature-1 |
2 | Rename branch | git branch -m <new-name> | Ex: git branch -m “feature-one” |
3 | Move to a branch | git checkout <branch-name> | Ex: git checkout feature-1 |
4 | List the all branches | git branch or git branch –lor git branch –list | |
5 | Merge branch from existing | git merge <another-branch> | Ex: git merge master |
6 | Delete a local branch | git branch -d <branch-name> | Ex: git branch -d test-branch |
7 | Delete a Remote branch | git push origin -d <branch> | Ex: git push origin -d test2 |
8 | Commit a code at a stage | git commit -m “commit1 or any” | |
9 | To see commit for branch | git log –oneline |