Sunday, September 12, 2021

 GitHub - Branching - time now 


Branching makes sure the code that is being delivered is in the best state possible. This feature can be utilised for isolating the development and testing of new features from working code that is running on a production environment. New applicaiton features should be build in a brach, test and then merged.

There should be

  1. Main branch (having the production code)
  2. Development Branch (latest code from main brach for developers)
    1. Feature Brach - Create new features taking the development brach code. Conventionally, new features are to be created in feature branches from the develop branch, and, once the feature has been developed, the code can be reviewed by a peer in a Pull Request and deployed to a test environment for Integration or User Acceptance Testing.

If all testing and reviews pass, the Pull Request can be approved and merged into the develop branch.

Releases : When there is a release approaching, a release candidate branch can be made. On this new branch, further testing of all the new features working together can take place, and more candidates can be made on this branch to amend any issues. Once merged into the master branch, the code can be tagged or marked as a release on the Git service that you are using. Changes must also be merged back into the develop branch, so that any changes that were made to the release candidate will also be included in future releases.

Commands for creating and deleting Branches
git branch

To create a new branch, the command is:

# git branch [NEW_BRANCH_NAME]
git branch develop

If you want to work on a new branch straight away, you can create a branch and checkout to it at the same time:

# git checkout -b [NEW_BRANCH_NAME]
git checkout -b develop

When you have finished working on your branch, and your code has been merged to main, it is good practice to delete the branch:

# git branch -d [BRANCH_NAME]
git branch -d feature-123

You can do this during Pull Request and if you aren't closing a Pull Request but still need to close a branch, delete a branch on your remote repository (again, likely on GitHub):

# git push --delete origin [BRANCH_NAME]
git push --delete origin feature-123
The key commands are summarised below:
git branch (check branches)
git branch [name] (create a branch with the name supplied)
git checkout -b [branch name] (checkout th branch)
git branch -d [branch name] (delete the branch - after your merge or work is finished)
git push --delete origin [branch name] (while completing pull request complete the delete branch too)

If you have queries, do drop in your queries below.

...HaPpY CoDiNg
Partha 

No comments:

Post a Comment