Search code examples
gitlocationgit-remote

using git remote command outside the repository dir


Is there any way to pass a location of the repository to the command git remote so the command will take it as a subject to work on?

I want to call

git remote add origin <url>

outside the repository directory, is it possible to pass the repository location as a parameter to the command?

git remote documentation - do you see any ways to do that?


Solution

  • https://git-scm.com/docs/git#git--Cltpathgt

    git -C <path>
    

    Run as if git was started in instead of the current working directory.

    https://git-scm.com/docs/git#git---git-dirltpathgt

    git --git-dir=<path>
    

    Set the path to the repository. This can also be controlled by setting the GIT_DIR environment variable. It can be an absolute path or relative path to current working directory.