Git Commits As a Beginner: Best Practices 2021

Git Version Control

ยท

2 min read

Git Commits As a Beginner: Best Practices 2021

Git best practices u should learn to do every day. Here are the most useful ones ->

What Is a Commit in Git?

git commit -m "this is a commit message"

The "commit" command is used to save your changes to the local repository. Using commits has to be done manually and explicitly with its commands. To know more about commands check Top Git Commands

Some Best Practices in Git commit

  • Simple and Single Impetus Commits

It is easier for the team/developers to see and understand the submitted commit messages when only related changes are done.

And if something Is wrong, small commit messages make it easier to revert bad checked code, which will eventually help you maintained the codebase.

  • Test the Code and Ask for Reviews

You should test your code often, and commit once. Bad commits make tracing bugs and resolving conflicts a nightmare. Using code reviews can promote knowledge sharing and code reuse in the future.

While javaScript ->
console.log("this is the best tester and debugger in Javascript")
  • Short and Detailed commit messages

Writing a summary of the block of your code should be in present tense(see below).

wrong practice ->
git commit -m "tested: fixed test in IE/Edge"
right practice ->
git commit -m "test: fix test in IE/Edge"

jon-tyson-RUsczRV6ifY-unsplash.jpg

Keeping in mind that your team should be able to read and understand the commit messages exactly what you have done or made or written.

  • Branch and Commit frequently

With short-term branches, you reduce check-out times, improve traceability, and expedite code reviews. By committing more frequently, you help to eliminate confusion and decrease the chance of a time-consuming merge.

creating a different branch will help minimize bad check-ins and reducing fewer code errors. committing often will help debug the bad check-ins.

If you learn something here, make sure u drop a ๐Ÿ’•.

Follow to learn and get to know more. Check out my profile for all my social accounts

ย