Blog of Denis VOITURON

for a better .NET world

Git - Best practices

Posted on 2018-08-26

Since some times, I work with several developers in my team. They are all connected to a GIT repository (TFS or VSTS) and they regularly ask me when and how to create a Pull Request efficiently.

After several articles on the subject and several weeks of use, here are my conclusions.

Commit Rules

  1. Commit as often as possible.
    • At least once a day
    • Please check that the code compiles correctly.
  2. Commit only the source code.
    • .cs,.ts,.xaml,.html, resources, ...
    • Use the file .gitignore to help you
    • Don't commit your compilation results, Nuget or NPM packages
  3. Write a clear and explicit comment.
    • To help the code review process
    • To help write Release Notes
    • To facilitate subsequent maintenance
    • Start your comment with Fix, Add or Change
    • Use short comments (maximum 80 characters)
    • Reference the associated Work Items via #


When you start to write a new feature, create a branch that follows the clear conventions:

Git Branch

Examples: users/dvoituron/addhelpdocumentation, features/loginscreen, hotfix/statperformance

The 'develop' branch

This branch contains code usable for all developers. It is therefore important that its content is correct and that other developers can easily find their way around. To do this, we will merge the code being written, via the Pull Request process (see below).

As several developers regularly update this branch develop, it is interesting to be notified of an update. VSTS allows to define notifications to receive an email when a developer to modify the branch ‘develop’. In this case, it is advisable to run a rebase from ‘develop’ to your branch, to resolve possible conflicts as soon as possible (and to dispose of the latest changes).


Pull Request

Once the code is written correctly in its branch, it is time to create a Pull Request which will be checked and finally validated to be merged to the develop branch. To avoid conflict problems, it is advisable to regularly update your branch with the new codes pushed in ‘develop’ (see above).

The Pull Request process is quite simple, and is mainly done online:

  1. Merge (merge or rebase) one last time the development code to your branch, to avoid conflicts.
  2. Compile your code locally and run all unit tests.
  3. Start the Pull Request process (via VSTS or TFS): click on the [Pull Request] button and choose to merge your branch to develop.
    • Give a specific title to the Pull Request. It corresponds to the functionality under development.
    • Describe in detail the content of the feature. This Description field and references to Work Items can be used to write Release Notes.
    • Check or specify Code Reviewers.
  4. The request is pending until Reviewers check the quality of the code. If necessary, they can add comments or adapt the code and commit the Pull Request which will then be updated.
  5. Once the review process has been completed, the last Reviewer (or manager) approves the Pull Request :
    • Merge into Squash mode to compress all commits into a single commit in 'develop' branch. This makes the development history much more readable.
    • Delete the feature branch, which has become useless. Work history and commits are kept in the Completed Pull Request.


A 5 minute demo is available here.



Follow me

Recent posts