1

I am using zsh on an Ubuntu 16.04

Since today I have not been able to use the cd command. Whenever I try to change my directory from the terminal I get this error fatal: Not a git repository (or any of the parent directories): .git

I took a look at my .zshrc to see if an alias might have changed cd to a git command, but I couldn't find any.

I was making some changes to my .zshrc today and I did see an error message after making those changes and reloading the shell but I ingored it and once I changed my config back to the way it was and I reloaded the shell the error/warning went away but after that I noticed that cd wasn't working.

Is there a way I can see or trace what program a unix command is hitting so that I can get to the root of this problem

EDIT: My zsh autocomplete works with cd but when I press enter I get this error.

This is the output of which cd

cd () {
    if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]
    then
        git push origin "${*}"
    else
        [[ "$#" = 0 ]] && local b="$(git_current_branch)" 
        git push origin "${b:=$1}"
    fi
}

1 Answer 1

1

You can try to check what is linked to cd with this command

which cd

If the setup is standard, you should get this message:

cd: shell built-in command

If it's not the case then you can see what causes the problem.

If you are using oh-my-zsh, this can come from it too since it's a git-based project.

6
  • I have updated my post with the output of which cd can you please take a look @NathanJ ? Jul 26, 2019 at 13:58
  • How do I set it back to the original shell command? Jul 26, 2019 at 13:58
  • My bet is that this function is defined somewhere in your zshrc or by files that you include in the zshrc. You need to remove it (Or change its name depending on where it is used)
    – Nathan J
    Jul 26, 2019 at 14:04
  • @LemmyKillmister unset -f cd or unfunction cd.
    – Kusalananda
    Jul 26, 2019 at 14:08
  • I checked my .zshrc this function is not there, I don't even remember writing it. Jul 26, 2019 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.