$ PATH中有多个git时,会使用哪个git版本?

I have a system installed /usr/bin/git and a local ~/bin/git. Both are in $PATH.

  • Which git will go get ... use? I'm assuming the first one it can find in $PATH, which usually would be /usr/bin/git.
  • Is there a way to force go get ... to use a git binary from a different path and not the first one it can find? e.g. ~/bin/git or /some/other/path/to/git.

Create an alias for go where you set the path environment like you want.

Then it will run in that environment, and won't be concerned with your environment.

As you stated, you created an alias like this:

alias go="env GOROOT=$HOME/go GOPATH=$HOME/gocode GOBIN=$HOME/gocode/bin PATH=$HOME/go/bin:$HOME/bin:$GOBIN:$PATH $HOME/go/bin/go"