I`m writing a Powershell script that (among other things) fetches some data from a Git repository. Normally, I would do something like this:
# Verify that the repo exists, otherwise create it
if(!(Test-Path $local-repo-path)){
git clone $repo-url $local-repo-path
}
cd $local-repo-path
git pull
cd "some-inner-directory\..."
# do various tasks here...
cd ..
# Perform other tasks...
As you can see, I'm navigating into the folder structure in the repo here in order to perform a set of tasks. It seems to me that it would be a lot cleaner to stay outside of the repo in Powershell, and pass the necessary paths in as parameters when needed. In other words, I'd like to avoid using cd <somepath>
, and cd ..
.
I can do that for most operations, but not for git pull
.
My question: Is there any way to perform a git pull
from outside of the repository directory? I.e., something like the following (this is invalid syntax):
git pull $local-repo-path