DEV Community

Cover image for 7 habits for better git usage
Dong Nguyen
Dong Nguyen

Posted on

7 habits for better git usage

  • everything begins with an issue
  • always check the current branch before making any changes
  • run "git pull" as often as possible
  • commit as soon as possible
  • commit should be referenced to the related issues
  • never push changes to the main branch directly
  • always keep the tree tidy by cleaning old branches

Top comments (4)

Collapse
 
dmshvetsov profile image
Dmitry Shvetsov • Edited

I can suggest

Make commits with atomic changes. Even better if you expand this advice to Pull Request.

and

Write good commit messages, the previous advice will make it easier. Good commit messages serve you as additional documentation.

Collapse
 
ndaidong profile image
Dong Nguyen • Edited

yes, commit message should be concise, clear and meaningful. There are some rules to write good commit messages, depending on the git flow you choose. What I mentioned here are general.

Collapse
 
tosbourn profile image
Toby Osbourn

Great habits!

This is the code I use for keeping local branches tidy. Sharing in case it helps anyone else.

git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
Collapse
 
rebaiahmed profile image
Ahmed Rebai

What about commits message on how it should be written? and how do your format your code before you changed it? and how about branch naming? and how about git rebase to fetch last changes in the main branches :')))))))