Is it possible you have inadvertently created a non-executable git-co
file somewhere? I can recreate your situation if I do just that, as demonstrated below.
$ git --version
git version 1.7.7.1.475.g997a1
$ git config --get-regexp '^alias\.co$'
alias.co checkout
$ git co b1
Switched to branch 'b1'
$ touch $HOME/bin/git-co
$ ls -al $HOME/bin/git-co
-rw-r--r-- 1 user user 0 2011-11-03 12:59 /home/user/bin/git-co
$ git co master
fatal: cannot exec 'git-co': Permission denied
$ for p in $(echo "$PATH" | sed -e 's/:/ /g'); do if [ -f "${p}/git-co" ]; then echo "Found git-co in ${p}"; fi; done
Found git-co in /home/user/bin
$ rm $HOME/bin/git-co
rm: remove regular empty file `/home/user/bin/git-co'? y
$ git co master
Switched to branch 'master'
Another thing you might want to try is enabling trace logging to get more information about what Git is doing. Following is an example:
GIT_TRACE=$HOME/trace.log git co master
You must use absolute paths if you want to send output to a file. Otherwise, use true
or 1
to send output to standard error; e.g. GIT_TRACE=1
. The trace.log
file contains:
trace: exec: 'git-co' 'master'
trace: run_command: 'git-co' 'master'
trace: alias expansion: co => 'checkout'
trace: built-in: git 'checkout' 'master'
If you do not see the trace: alias expansion: co=> 'checkout'
trace log output, Git is finding a git-co
file in the PATH
environment variable. Git uses a PATH
as follows:
- Start with an empty
PATH
, saving any "old" PATH
for reference.
- If the
--exec-path=<my git commands path>
Git option is found, append <my git commands path>
to the PATH
.
- If
--exec-path=<my git commands path>
was not found and the GIT_EXEC_PATH
environment variable is set, append this to the PATH
.
- If you called
git
using a relative or absolute path, append the absolute path of the git
executable to the PATH
.
- If
PATH
was previously defined, append it to the PATH
.
- If
PATH
was not previously defined, append /usr/local/bin:/usr/bin:/bin
to the PATH
.
You can use another alias to get Git to tell you what it is setting the PATH
environment variable to.
$ git config --global alias.whatpath '!echo $PATH'
$ git whatpath
/usr/local/libexec/git-core:/home/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Then check each directory listed for the existence of a git-co
file. It's not sufficient to do which git-co
and assume that if nothing is found that you do not have a git-co
file located in one of the directories in Git's PATH
; a file may exist that is not executable and which
will not display it.
git config --get-regexp '^alias\.'
/usr/libexec/git-core
,/usr/lib/git-core
or one of those with/usr
changed to/usr/local
. You should see a bunch of executable files for all the git commands. See if there's also agit-co
in there, which is executable by root but not by you. Possibly this could also happen if thisgit-co
file is somewhere in yourPATH
. It might also be locatable withsudo which git-co
, if it's not in the git install directory.alias.co checkout