Changing the default directory for git repositories

Is it possible to change the default/root directory of where git looks for projects so you can clone a project like this:

git clone git@myserver.com:project.git

rather than like this:

  • Can't get git flow to apply to other users in Sourcetree
  • gems error on windows - “openpath: pathname too long”
  • Git: “could not read from remote repository”, when remote is another local repo
  • GAE: Trouble with push to deploy
  • Delete a file from a Git repo with an apostrophe or quote in the name
  • Can I have git gui and git bash and eclipse git plugin looking at same repo simultaneously?
  • git clone git@myserver.com:/var/www/html/project.git
    

    I’ve seen git --git-dir=<path> in the help page but it seems that it only takes effect for that particular command rather than being a global setting – and that’s even if it does what I want it to do.

    Can anyone help?

  • find out who created a branch on a remote git repository
  • Git: Show every line added by user in current branch
  • Git-tfs fetch and diff
  • git pull very slow (not the ssh transfer part) on Windows 2003 server
  • How do I switch to a new branch in git
  • Detached HEAD Issue in Android Studio
  • 3 Solutions collect form web for “Changing the default directory for git repositories”

    When you’re using ssh path, it always start in given user’s home directory. So for the example in the question to work, all you have to do is set HOME directory of git user to /var/www/html.

    When using the git protocol, you can set it on the server by giving git daemon the --base-path option.

    Well, before all other: you use scp-style notation, standard URLs will be better for communication

    Back to question: Yes, you can do it

    if you want to use a different format for them (such that the URLs you
    use will be rewritten into URLs that work), you can create a
    configuration section of the form:

        [url "<actual url base>"]
                insteadOf = <other url base>
    

    in your example it will be

        [url "myserver.com:/var/www/html/"]
                insteadOf = myserver.com
    

    or even

        [url "git@myserver.com:/var/www/html/"]
                insteadOf = myserver:
    

    for using URL myserver:project.git

    Git Baby is a git and github fan, let's start git clone.