Everywhere but at $z=0$, the function $z\mapsto\frac{1}{z}$ is holomorphic, so the integral around any closed, piecewise-smooth curve that does not contain the origin will be $0$.
In the diagram below, there are two paths, the orignal path following the red arrows (enclosing the red region), and the additional path following the green arrows (enclosing the green region).

The path integral along the original red path and the path integral along the additional green path cancel each other out along the boundary between the red and green regions (the red path and green path are in opposite directions, so $\mathrm{d}z$ on one path is the negative of $\mathrm{d}z$ on the other at the same point). Thus, we can combine the two path integrals to make one path integral along the path surrounding the union of the red and green regions. If a function is holomorphic in the green region, then the path integral around the union is the same as the integral around the red region since the integral around the green region is $0$.
In this way, we can modify paths through regions where a function is holomorphic without altering the value of the integral. However, if there is a point at which a function fails to be holomorphic (a singularity), we have to be careful.

In the diagram above, the point in the middle is a singularity. Suppose we want to extend the path surrounding the red region to contain the blue and green regions. By the argument above, the integral around all three regions is the sum of the integrals around each. Assuming the function is holomorphic in the green region, the path integral around the green region is $0$, so the integral around the union of the three regions is the integral around the original red region plus the integral around the blue region.
For the function $z\mapsto\frac{1}{z}$, it is easy to compute that the integral around the origin is $2\pi i$. Thus, extending the path of integration through a region with no singularities does not change the integral (as in the first diagram) and extending the path of integration though the origin increases or decreases the integral by $2\pi i$ (as in the second diagram). Thus, $ \frac{1}{2\pi i}\int_\gamma\frac{\mathrm{d}z}{z} $ will be an integer.