Git & Github Practices To Follow For Effective Software Development

Β·

3 min read

All around the world people use Git & Github for collaboratively working on code. There are some best practices that you should follow to use these tools extremely efficiently. I have observed that these practices improve the developer productivity if used properly. So listing the below in no particular order:-

  1. Frequency of commits:- You should commit your changes as frequently as possible. The rule of thumb which I follow while doing commits is that one commit per function written. This allows my commit history to be really descriptive of all the changes I have made while developing a feature.

  2. Name of the branches:- You should name your branches in the format <tag>/<short-name> .
    The tag can be any of the below:-

    1. feat -> Indicate that the branch is for the feature development

    2. fix -> Indicate that the branch is for the bug fixes

    3. hotfix -> Indicate that the branch is for P0 bug fixes which need to go live ASAP.

    4. refactor -> Indicates that the branch is for refactoring the code.

    5. style -> Indicates that the branch is for the CSS styling changes in case of web development.

    6. chore -> Any other type of work which doesn't involve any of the above categories.

So for example, if you are developing the feature of a shopping cart in an e-commerce site then the name of your branch can be feat/shopping-cart .

  1. Commit messages:- Your commit messages should also follow a particular format which is tag: message describing the change . The tag is similar to the tags mentioned in the branches.

  2. Pre-commit hooks:- Pre-commit hooks are the set of commands that runs to do certain things. Pre-commit hooks are specially used to check for formatting & linting issues in the code. If there are some issues in your files, your commit gets rejected. This allows you to keep standard code formatting across the developers in your project.

  3. Setup PR template on GitHub:- While raising a PR there should be a fixed template that the developer can fill so that the person reviewing the PR gets all the necessary information about the change, why it was done etc. You can setup pull_request_template.md file which allows you to create a PR template to follow.

  4. GitHub workflows:- With GitHub workflows you can run integration & unit tests for your PR changes, can check for linting & formatting issues, can do code analysis for smells & duplication in the code. GitHub workflows are a great way to ensure that before anyone raises the PR the code compiles & runs. It is very easy to setup GitHub workflows for your project.

So hope you would have got an idea about the best practices in Git & GitHub. If you have any suggestions feel free to add them in the comments below. Please press like if you liked the content. Do follow me on my YouTube channel where I am publishing a lot of great content.

Did you find this article valuable?

Support Abhijeet Gurle by becoming a sponsor. Any amount is appreciated!

Β