Git, best practices and mistakes.

Here we are going to talk about the best practices that you should follow and avoid the mistakes at all cost while using git. These are all the points learned during the experience of various project and mistakes. So lets start.

  • Daily push your code before leaving and pull the code before start working. Why this is important is because it keeps your project updated and also lead to less merge conflicts. Also when you push daily everyone else will be aware of your changes and merge to avoid future conflicts. Solving conflicts in small code is easy as compared to bulk conflict resolution

 

  • Try to keep your sub branches consistent. Lets say we have a branch A  , we make two more branch and C for two different features. In this case try to keep B and C consistent to A as much as possible. How will you do it? After every major change in B, merge the branch A to B and push changes to A so that for every major change in C when we merge the changes from A we will have the changes of B also. This will lead to git conflict which will be easy to solve with respect to making all the merge at the end of both the feature branch.

 

  • Dont push the modules that are installed by commands like npm install, bundle install or others as these will only increase the size of your repository. Also they may lead to git conlict if they are updated to two different version on two branches.

 

  • Avoid usage of flags like –force or -f. These will force the task to be done instead of considering the errors that may occur due to that specific task.

 

  • Merge permission should only be with the master and should not be given to everyone as one wrong merge will lead revert. Avoid revert, rebase as much as possible.

 

  • Use gitignore:  If your project has various secrets in it .gitignore is must to have. Add your secret files here which will prevent any secrets to be pushed in repository. Try reading ore about it here Git ignore documentation.

Gaurav Yadav

Gaurav is cloud infrastructure engineer and a full stack web developer and blogger. Sportsperson by heart and loves football. Scale is something he loves to work for and always keen to learn new tech. Experienced with CI/CD, distributed cloud infrastructure, build systems and lot of SRE Stuff.

1 COMMENT
  • Want to host your own git. Learn how to host gitlab locally? - Learn Steps
    Reply

    […] Git, best practices and mistakes. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.