Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you determine the location of the git-core folder dynamically?

Tags:

git

A quick google says that the folder should be located at /usr/share/git-core but I think this differs depending on the way it was installed since mine is located at /usr/local/share/git-core and my colleague's is somewhere else.

Is there a command or variable available to output the absolute location of git-core?

like image 837
Mark Stickley Avatar asked Feb 05 '23 04:02

Mark Stickley


1 Answers

$ git --exec-path
/usr/lib/git-core

Overridable via an argument to that flag or with GIT_EXEC_PATH environment variable.

If you have multiple copies of git, then try ~/homebrew/bin/git or /usr/bin/git or whatever the path to Xcode's copy is.

The full story of how git finds subcommands is actually straightforward: It finds the value of exec_path -- either from argv, the environment, or the compile-time value. Then it pushes this onto the front of PATH.

/*
 * We use PATH to find git commands, but we prepend some higher
 * precedence paths: the "--exec-path" option, the GIT_EXEC_PATH
 * environment, and the $(gitexecdir) from the Makefile at build
 * time.
 */
setup_path();

(Contrary to what this comment implies, it just picks one of those.)

Much older versions of git just polluted your path with all the git-whatever commands.

If you're trying to diagnose or bandage something funky, you could try manipulating PATH with whatever the correct path to git-core is, but it's much more likely that invoking the correct copy of git will work.

$ echo '/usr/bin/env' > ~/local/bin/git-env
$ chmod +x ~/local/bin/git-env
$ env - PATH=~/local/bin /usr/bin/git env
PATH=/usr/lib/git-core:/home/josh/local/bin
PWD=/home/josh
$
like image 134
Josh Lee Avatar answered Feb 07 '23 18:02

Josh Lee