how do I add the 'tree' command to git-bash on Windows?

I'm using git-bash on Windows 7. I'd like to see a tree of the current directory. However:

jcollum@DEVELOPER01 ~/Dev/express_coffee
$ tree .
sh.exe": tree: command not found

OK, so I don't have the tree command. How do I install it? I found an article but it was for Macs.

2

11 Answers

You could also use "cmd //c tree" to use Windows' tree

Explanation:

  • Launch cmd with '/c' argument and run tree, then terminate

/C Carries out the command specified by string and then terminates

(extra slash for escaping)

/a use to run with ascii chars in case it doesn't display right.

Answered in greater detail here:

5

I have downloaded the tree.exe inside the zip file from here as suggested.

Then I have extracted the tree.exe file to C:\Program Files\Git\usr\bin (I have added this folder to windows path to make it work with the regular CMD but it works with GITBash too).Git Bash with tree command on windows

I hope this helps you somehow !

3

There is a tree command in windows already — only problem is it is tree.com and git bash will not automatically add extension .com and execute it.

However it will find it if you press tab after you type tree or tre

To see files you have to use //f — you have to use // or bash will think it is folder name

I also used //a to show ascii lines but you don't have to use it

Example:

dean@dean:~/java$ tree
bash: tree: command not found
dean@dean:~/java$ tree.com //a
Folder PATH listing for volume c
Volume serial number is 4E70-B37A
C:.
+---atom
+---sublime
\---vscode
dean@dean:~/java$ tree.com //a //f
Folder PATH listing for volume c
Volume serial number is 4E70-B37A
C:.
+---atom
| test1
|
+---sublime
| test2
|
\---vscode test3
dean@dean:~/java$
1

The GnuWin32 build of tree is at - you'd need to add it to your path manually if you're not already using GnuWin32.

If you want to use it at a Windows console also you'd need to rename or copy tree.exe to something else, e.g. lstree.exe, otherwise the Windows tree command will take precedence. The advantage of the GnuWin version is that it has lots of options - e.g. tree -L 2 would limit the recursion depth to 2.

> tree --help
usage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]] [-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes] [--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset] [--filelimit #] [<directory list>] -a All files are listed. -d List directories only. -l Follow symbolic links like directories. -f Print the full path prefix for each file. -i Don't print indentation lines. -q Print non-printable characters as '?'. -N Print non-printable characters as is. -p Print the protections for each file. -u Displays file owner or UID number. -g Displays file group owner or GID number. -s Print the size in bytes of each file. -h Print the size in a more human readable way. -D Print the date of last modification. -F Appends '/', '=', '*', or '|' as per ls -F. -v Sort files alphanumerically by version. -r Sort files in reverse alphanumeric order. -t Sort files by last modification time. -x Stay on current filesystem only. -L level Descend only level directories deep. -A Print ANSI lines graphic indentation lines. -S Print with ASCII graphics indentation lines. -n Turn colorization off always (-C overrides). -C Turn colorization on always. -P pattern List only those files that match the pattern given. -I pattern Do not list files that match the given pattern. -H baseHREF Prints out HTML format with baseHREF as top directory. -T string Replace the default HTML title and H1 header with string. -R Rerun tree when max dir level reached. -o file Output to file instead of stdout. --inodes Print inode number of each file. --device Print device ID number to which each file belongs. --noreport Turn off file/directory count at end of tree listing. --nolinks Turn off hyperlinks in HTML output. --dirsfirst List directories before files. --charset X Use charset X for HTML and indentation line output. --filelimit # Do not descend dirs with more than # files in them.

Compared to the Windows tree:

> tree /?
Graphically displays the folder structure of a drive or path.
TREE [drive:][path] [/F] [/A] /F Display the names of the files in each folder. /A Use ASCII instead of extended characters.
2

Git for Windows () (has Git Bash) but it does not include tree. tree is available for via pacman (Package Manager) but that is only available if you install "Git for Windows SDK" (scroll to the bottom of which provides a link to download installer for it from )

This SO: "Package management in git for windows?" was very helpful

Also as commented in the above SO, they link to this git for windows issue [Pacman missing on fresh 2.5.2 install #397] that it was intended to not include pacman in the default install.

Anyways, I installed "Git for Windows SDK", then in it's bash prompt (SDK-64) I ran the following to install current tree v1.7.0-1 (as of this posting Aug 30, 2018):

[SDK-64: Bash Terminal for Git for Windows SDK]
pacman -S tree
...
Proceed with installation? [Y/n] Y

On my system, Git for Windows SDK is installed under: C:\git-sdk-64, so from my Git for Windows Bash shell (that did not have tree installed), I copied it over tree.exe to it's /usr/bin directory, e.g.

[MINGW64: Bash Terminal for Git for Windows]
cd /usr/bin
cp /c/git-sdk-64/usr/bin/tree.exe .

Now I can run tree v1.7.0 from both Git Bash shells.

So, to make it even easier for others and maybe myself on a future machine, I looked at where pacman was getting the tree package from by running following in my Git for Windows SDK Bash terminal:

$ pacman -S --info tree
Repository : msys
Name : tree
Version : 1.7.0-1
Description : A directory listing program displaying a depth indented list of files
Architecture : x86_64
...

The key thing, here is that pacman is getting it from the "msys" repository (FYI: even though it says msys, it really is using msys2), so I looked at /etc/pacman.d/mirrorlist.msys and the first mirror points to

So next time you want a package that is NOT in Git for Windows, you can download them from: (for 64-bit) or from (32-bit)

e.g. direct download link for tree v1.7.0-1

  • 64-bit:
  • or
  • 32-bit:
  • or
1

git-bash is really just a cut down version of mingw. Install Cygwin from cygwin.com, and then either use the package manager to install 'tree' or whatever package it's in, or if it doesn't exist, then install gcc, download the tree source from here:

Then follow the instructions in the INSTALL file (make, make install)

2

Another option would be to use the MinGW package, if you already have MinGW installed, tree is packaged there, just install it by opening a MinGW terminal and running pacman -Sy tree.

If you don't have MinGW installed already it's probably overkill to install it just for the tree command.

In windows 10 locate tree.com and copy it as tree.exe in the mingw bin folder (in my case C:\Program Files\Git\mingw64\bin)

You must install the Three for Windows as said above by the link:

Besides that you need to add the tree program to your windows path or the tree command will be available only on cmd. Access your windows path and add this (for default installation):

;C:\Program Files (x86)\GnuWin32\bin

Them you will be able to use tree command on git bash on windows.

This is the beginning of my .gitconfig file : I made an alias for log --graph

# This is Git's per-user configuration file.
[user]
# Please adapt and uncomment the following lines: name = xxxxxx email =
[alias] tree = log --graph --oneline --all --pretty=format:'%C(yellow)%h%Creset -%Cred%d%Creset %s %Cgreen%cr%Creset %C(cyan)%an%Creset %gn'
1

I use Windows Terminal in Windows 10, whenever I need this, I switch the terminal just typing cmd, after I get what I need, I can change the terminal cmd -> bash with typing bash

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like