DEV Community

Sura
Sura

Posted on

Git Best Practices: Tips and Tricks

Happy new year!Git is an essential tool for version control in modern development workflows. While many developers are familiar with basic commands like git add and git commit, there are numerous advanced techniques that can streamline your workflow and help manage complex codebases. This blog post dives into several practical Git commands and tips to help you level up your Git game.

Git add: Why git add -p is Better Than git add .

When working with Git, adding changes to the staging area is a critical step before committing your work. While git add . is commonly used for convenience, git add -p offers more control and insight into your changes. Here's why git add -p is often the better choice.

When to use git add -p

You’ve made multiple changes, but only want to commit some of them.
You want to separate unrelated changes into different commits.

git add -p
Enter fullscreen mode Exit fullscreen mode

When to Use git add .

git add .
Enter fullscreen mode Exit fullscreen mode
  • can be useful when: You’ve made simple, isolated changes, and you’re confident all of them should be staged.
  • You’re in a rush to stage everything quickly.

Top comments (0)