Skip to content

Add to Documentation - wp-cli for windows using gitbashΒ #592

@Craigeniah

Description

@Craigeniah

Hello,

I spent most of my day trying to troubleshoot why the wp-cli was not working correctly on my windows machine.
As it turns out it was the git bash portion that was not allowing it to work. I use git bash as my command line tool of choice.

I think it would be helpful to many to add this detail to the documentation located here.

The solution I found from here: https://maheshwaghmare.com/setup-wp-cli-wordpress-command-line-interface-on-windows-operating-system/#not-work-on-git-bash

Not work on Git Bash?

Create another file wp without any extension into the C:\wp-cli\ directory and paste below code:

#!/usr/bin/env sh

dir=$(d=${0%[/\\]*}; cd "$d"; pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
   # Cygwin paths start with /cygdrive/ which will break windows PHP,
   # so we need to translate the dir path to windows format. However
   # we could be using cygwin PHP which does not require this, so we
   # test if the path to PHP starts with /cygdrive/ rather than /usr/bin
   if [[ $(which php) == /cygdrive/* ]]; then
       dir=$(cygpath -m $dir);
   fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/wp-cli.phar" "$@"

Great!

Now open git bash and type command wp Eg.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions