Git Best Practices


Git is a robust version control system, it provides developers with vast functionalities helping maintain high quality code base. Here are some of my experiences with Git which I think is really helpful in day to day interaction with git as well helping you and your team be more productive with the code.

Using Feature Branch

Branches are one of the best features of git so why not use this functionality to split your code based on work area. If you are working on a dedicated feature, Use Feature branches off the master branch for any task. Use Pull Request to merge code back to master this helps to encapsulate your work, track changes.

This techniques if useful, if you have many people work off same code base. Working off feature branch helps to minimize merge conflicts and share code amongst many developers working on common feature

Using Rebase to Squash your commits

# Merge Last 5 Commits to Single Commit
git rebase -i HEAD~5

Pick the earliest commit and squash rest of the commits, by selecting squash for the commits you want to squash together. You will also have option to update the commit message for the rebase so that you can include all the details of all the commits you are combining.

Pulling Changes from master with rebase

git pull --rebase origin master