Geodesic between two points
Solution 1:
A Riemannian manifold (assume it to be connected) is said to be complete, if it is complete as a metric space with respect to the distance function arising from minimizing the length of curves joining two given points.
It is said to be geodesically complete, if every geodesic can be extended to all of $\mathbb{R}$ (with a constant speed parametrization).
A famous theorem (the theorem of Hopf-Rinow) says, that these two definitions coincide. In that case some other interesting properties are known to hold, like: for any two points there is a length minimizing geodesic joining these points. You may want to look it up somewhere.
In general, global questions of this kind are difficult but also very interesting. Key results in that direction are based on the theory of Jacobi fields and resulting comparison theorems. A classic is the book of Cheeger and Ebin.
You may try to search for 'Global differential geometry'.
For immersions in $\mathbb{R}^n$ another difficulty arises, when the immersion is not an embedding.
Solution 2:
Given a surface $S \subset \mathbb{R}^3$ defined by a smooth immersion as indicated, there need not be a smooth geodesic connecting a given pair of points.
For example, let $S$ be the punctured $xy$-plane, $$S := \{\,(x, y, 0) : (x, y) \neq (0, 0)\,\}. $$ Then, there is no smooth geodesic in $S$ connecting, say, $(-1, 0, 0)$ to $(1, 0, 0)$.
Solution 3:
if your set/manifold is compact then it means it is geodesically complete(Hopf-Rinow theorem). Thus you can extend your curve to R. For example, SO(n) is geodesically complete. If we are talking about a unique distance minimizing curve then every point on the manifold has a certain local domain where the uniqueness condition holds. For further detail, look at the cut-locus concept.