Work Done by Gravitational Force [Bit a long question]
Here in this question, I need to know clear my doubts on Gravity, more precisely Work done by a Conservative Force(here, gravitational force).
Ok, suppose there is an object lying. Neglect any damping force like friction, etc.
Now, suppose a force(it could be consevative or non-conservative force) acts on the object. It displaces from it's position.
Now, if the displacement is in the direction of that force, then the work done by the force is Positive.
And, if the displacement is in opposite direction of that force, then the work done by the force is Negative.
I think the above statements are true for any kind of force(conservative/non-conservative).

Now, we'll come to the main part of the question.  

1st Part
Suppose a mass m is at point P, r distance away from another mass M.
The mass m will experience gravitational force, $\vec{F_g}$ towards mass M.
Now , an external force $\vec{F}$ acts on the object of mass m which moves it to $\infty$.
Assume a small displacement vector $d\vec{r}$ in directon of external force $\vec{F}$ for which there is no change in the gravitational force,  $\vec{F_g}$. Also, consider a unit vector $\hat{r}$ in the direction of external force $\vec{F}$.
Let dWg be the work done by gravitation for this little displacement, $d\vec{r}$.
dWg = $\vec{F_g}\cdot d\vec{r}$ = Fg dr cos 180°
dWg = - Fgdr -----------Eq.(1)
So, I think the gravitational force, $\vec{F_g}$ is doing negative work and the external force, $\vec{F}$ is doing the same positive work due to the sole reason that the displacement of object is in the direction of external force and opposite to gravitational force.
Now, $\vec{F_g}$ = -  $\vec{F}$ = $\frac{GMm}{r^2}$$\hat{r}$
So, in equation (1)
$$\int \, dW_g = \int_r^\infty - F_g \, dr$$
$$W_g= \int_r^\infty \frac{-GMm}{r^2} \, dr$$
$$W_g= -GMm \int_r^\infty \frac{1}{r^2} \, dr$$
$$W_g= -GMm \biggl[\frac{-1}{r}\biggr]_r^\infty$$
$$W_g= -GMm \biggl[\frac{-1}{\infty}-\frac{-1}{r}\biggr]$$
$$W_g= \frac{-GMm}{r}$$
So, $$W_g = {\color{red}{\int_r^\infty - F_g \, dr}} = {\color{green}{\frac{-GMm}{r}}}$$  
The above 2 equations are in agreement. Both equations, one in red and another in green colour will give negative work done by the gravitational force.

2nd Part
Now, we'll consider that the object of mass m is at $\infty$. 
Also, the object is taken from $\infty$ to point P which is again, at distance r from mass, M.
This time, the little displacement vector $d\vec{r}$ will be in the direction of gravitational force $\vec{F_g}$. Also, the unit vector $\hat{r}$ is in the same direction as well.Thus,  
$\vec{F_g} = \frac{GMm}{r^2}\hat{r}$
So, the work done by gravitational force will be
dWg = $\vec{F_g}\cdot d\vec{r}$ = Fg dr cos 0°
dWg = Fgdr -----------Eq.(2)
Here, the gravtational force, $\vec{F_g}$ will do positive work because the displacement of object is in the direction of gravitational force.
So , in equation (2),
$$\int \, dW_g = \int_\infty^r F_g \, dr$$
$$W_g = \int_\infty^r \frac{GMm}{r^2} \, dr$$
$$W_g = GMm \int_\infty^r \frac{1}{r^2} \, dr$$
$$W_g = GMm \biggl[\frac{-1}{r}\biggr]_\infty^r$$
$$W_g = GMm \biggl[\frac{-1}{r}-\frac{-1}{\infty}\biggr]$$
$$W_g = \frac{-GMm}{r}$$
So, $$W_g = {\color{blue}{\int_\infty^r  F_g \, dr}} = {\color{green}{\frac{-GMm}{r}}}$$  
So, finally my doubt:-
The blue equation tells that the work done by gravitational force is postive(beacuse the displacement vector is in same direction as that of gravitational force).
But, after integrating it, we have the same green equation which we derived it earlier which tells us that the work done by gravitational force is negative.
Now, if we look at the red and blue equations, both are same, just integrating the term in opposite order.
And we know that the gravitational force is a conservative force so whether it is the blue one or red one, the work by gravity will be same which is given by the green equation.

But at the end, my doubt is why the blue and green equations are inconsistent to each other (blue saying work by gravity is positive whereas green saying work by gravity is negative) ?
 A: Lets place the stationary mass $M$ a the origin. In both cases the gravitational force is towards the origin, and is given by
$$\vec{F}_{g}=-\frac{GMm}{r^{2}}\hat{r}$$
Thus in the first case, the work done by the gravitational force is
$$W_{r\rightarrow\infty}=\int_{r}^{\infty}\vec{F}_{g}\cdot\vec{dr}=-\int_{r}^{\infty}\frac{GMm}{r^{2}}dr=-\frac{GMm}{r}$$
On the other hand, in the second case we just need to sweep the limits of integration
$$W_{\infty\rightarrow r}=\int_{\infty}^{r}\vec{F}_{g}\cdot\vec{dr}=-\int_{\infty}^{r}\frac{GMm}{r^{2}}dr=\frac{GMm}{r}$$
which is exactly the opposite, and the signs are just what you've anticipated. An important thing to note is that also in both cases
$$\vec{dr}=dr\hat{r}$$
and the sign is set by the integration limits. So in the first case $dr>0$ and in the second $dr<0$ (in a very informal manner). You ignored this fact when you wrote $\cos\left(180^{\circ}\right)$ in the dot product in the second case.
A: In the second case at first you did scalar multiplication and got the sign. Now all becomes magnitude and no additional signs are allowed from integration. You might say "why?" Remember the definition of scalar multiplication.
${\vec A }{\cdot}{\vec B}={ABcos\theta}$
See the magic! After scalar multiplication you just get the magnitude and the cosine gives sign. So in your second case perform the integration inside a modulus . And just keep $cos\theta$ outside. Hence you get positive work
Alert: This method may not have mathematical rigor but it's powerful
