I am working on windows machine and I use bash shell which comes with Git. But there are many utilities which are missing in this version of bash shell.
How can I install more commands on this shell?
312 Answers
There are two versions of Git that you are likely to be using - the msysgit distribution or Cygwin.
Installing Additional Utilities For Cygwin
Although you might have only installed Git as a part of your Cygwin install (if you used Cygwin), Cygwin has a program called setup.exe which you can use to add packages. Essentially, all you have to do is run setup.exe and pick out what programs you want installed when you get to the Select Packages window. The introduction here provides a good overview with images that detail the process.
Cygwin's installer is smart enough to figure out that you have a preexisting installation, and it will add packages to your installation (instead of nuking it and starting over).
MSYS
The other version of Git you are probably using (if not Cygwin) is msysgit. Because msysgit installs a minimal Unix environment which is not really compatible with MinGW, you'll end up having to install the MinGW suite beside msysgit. The MinGW Getting Started page gives a detailed overview on how to go about getting MinGW installed - since I have no experience with MinGW personally, all I can really do is refer you to their instructions.
You'll then have to migrate your msysgit installation into MinGW. This can be accomplished by doing the following (taken from here). After the following sequence is done, MinGW should find your Git installation.
cd GITDIR # Where GITDIR is wherever inside Program Files you put Git
cp bin/git* /MINGW/bin # Where MINGW is wherever you put MinGW
cp -r libexec/git* /MINGW/libexec
cp -r share/git* /MINGW/share 6 With recent Git for Windows installations, installing additional shell scripts and programs is pretty easy.
Simply put the executables into C:\Program Files\Git\usr\bin (%ProgramFiles%\Git\usr\bin).
I recommend installing git using chocolatey choco install git --params "/GitAndUnixToolsOnPath /WindowsTerminal", because you can update git (and all other tools installed with chocolatey) by executing choco upgrade all.
Example for git-fresh
Copy the file git-fresh to C:\Program Files\Git\usr\bin.
Example for adr-tools
- Download a zip package from the releases page
- Unzip the package
- Copy everything from
src/intoC:\Program Files\Git\usr\bin
to add rsync
You can download the rsync file directly from mysys. Just search the page for rsync and choose the one with the latest date / latest version number.
Unpack this file (e.g. rsync-3.1.3-1-x86_64.pkg.tar.xz) via
tar -xf rsync-3.1.3-1-x86_64.pkg.tar.xzThen copy rsync at ./usr/bin/rsync.exeand paste it into the /usr/bin folder of your Git installation.
On my machine, that is C:/Program Files/Git/usr/bin/
You can see the location of your Git installation via
where gitHere is a GitHub gist by "hisplan" (Jaeyoung Chun) that has instructions along with a link to the 3.1.3-1 version of rsync: add-rsync-to-git-bash.
Note: I could not unpack the rsync-3.1.3-1-x86_64.pkg.tar.xz file directly into the Git folder, because permissions did not allow it. And Git Bash does not have sudo.
But I could unpack it directly into my Downloads folder no problem.
It's just as well, because you only need the rsync.exe file anyway.
If you are using msysgit a simple option is to just install MinGW and then add the MINGW path to the .bashrc file you are using for your Git installation:
PATH=$PATH:/MINGW/msys/1.0/bin...where MINGW is where you installed MinGW
That way you can use the MinGW tools directly from your Git bash installation, and if you need another bash tool you can just install it to MinGW.
You can download additional Unix unitities Wget, Hugo, Xpdf, make, Nano from here:
Wget
- Download the lastest wget binary for windows from eternallybored (they are available as a zip with documentation, or just an exe)
- If you downloaded the zip, extract all (if windows built in zip utility gives an error, use 7-zip).
- Rename the file
wget64.exetowget.exeif necessary. - Move
wget.exeto yourGit\mingw64\bin\.
Note: I have noticed some bugs when using Wget on Git Bash to create WARC files. For more complex use of Wget, consider Cygwin instead.
Hugo
Hugo static site generator can be downloaded as a binary and does not have a installer.
Dropping it into your bin easily adds it to your Git Bash path.
Grab the Windows 64-bit version from the releases page.
Unzip the download, then copy hugo.exe into your Git\mingw64\bin directory.
Xpdf
Xpdf is a handy utility for manipulating PDF files.
- Download the windows version "Xpdf tools".
- Extract zip.
- Copy the contents of
xpdf-tools-win-4.00\bin64\into yourGit\mingw64\bin\. - Check the docs to get started with tools such as
pdftotextandpdftopng.
make
- Go to ezwinports.
- Download
make-4.1-2-without-guile-w32-bin.zip(get the version without guile). - Extract zip.
- Copy the contents to your
Git\mingw64\merging the folders, but do NOT overwrite/replace any existing files.
Nano
As of 2018, recent versions of Git Bash include Nano, so this is unnecessary!
- Download the Nano binary from Nano win32-support page. You just need the
.exefile, which is namednano-git-0d9a7347243.exe(as of this writing). - Rename the file to
nano.exe, and copy to themingw64\bindirectory. - This version of Nano will not work with Git Bash alone, but can be invoked using
winpty, for example,winpty nano test.txt.
install "Git for Windows SDK" (scroll to the bottom of which provides a link to download installer for it from )
I found a pretty simple answer today that worked for rsync.
- Install git bash for Windows
- Download
rsyncfrom futureware.at* - Extract to anywhere, I choose
C:\rsync-3.1.2-2-x86_64.pkg - Add the bin folder to the top of your system path
* I do not know who is behind futureware.at, I would prefer to link to a more primary source.
1I tried the following and installed emacs to git-bash.. 1. Install msys2 somewhere(does not have to be same computer). 2. Under msys2, run the following:
cd /tmp mkdir -p var/lib cp -R /var/lib/pacman var/lib/ pacman -Sr /tmp emacs tar zcf emacs.tar.gz usr
Copy
emacs.tar.gzto where you can access from git-bash, then under git-bash:tar zxf emacs.tar.gz -C / emacs
That's all, good luck.
After the first post, I tried an other computer but not working. It turns out that some dlls is missing in git-bash. Then I tested in a clean virtual machine with the following steps:
Install msys2-x86_64-20180531 and Git-2.19.1-64-bit.
Update msys2, open msys64 console and run:
pacman -SyyuClose msys64 console when prompted, then run the above command again.
Get emacs files as the previous steps(run the following in msys64):
cd /tmp mkdir -p var/lib cp -R /var/lib/pacman var/lib/ pacman -Sr /tmp emacs tar zcf emacs.tar.gz usr mv emacs.tar.gz /c/tmpps: I once tried the above steps in /d/tmp instead of /tmp and was not able to install emacs to it.
Open git-bash and extract emacs files:
cd /c/tmp tar zxf emacs.tar.gz -C /It will complain missing shared library "?" on trying to run emacs now. The "?" will not revealed to any readable
Go back to msys64 and get the msys2 dlls's:
ls --color=never /bin/*.dll > /c/tmp/1.txtIn git-bash compare dlls with msys:
cd /c/tmp git init git add 1.txt && git commit ls --color=never /bin/*.dll | sed 's#\*$##g' > /c/tmp/1.txt git diff 1.txt | grep '^-' | sed '1d' | sed 's#^-/bin/##g' > diff_dlls.txtIn my case, there are 26 dlls in diff_dlls.txt.
Copy the dlls from msys64 to git-bash:
In msys64:
mkdir /c/tmp/dlls cat /c/tmp/diff_dlls.txt | xargs -I {} cp /bin/{} /c/tmp/dllsIn git-bash:
cp /c/tmp/dlls/* /binAll done, now emacs runs in git-bash. Some of the 26 dlls may not be necessary, but I'd prefer to save my time instead of disk space.
If using Git bash for Windows (MinGW64), I had a very hard time getting rsync to be added to it. kept getting error: dup() in/out/err failed
Instead, using Cygwin worked eventually.
Steps I took to use rysnc in Gitbash for Windows
- Install gitbash for windows
- Install cygwin64
- Add the cygwin path to the Windows path variable
Windows-> System->advanced Setings->Environment Variables
Add a path for C:\cygwin64\bin\
- Close and re-open gitbash Now gitbash will find the rsync.exe in the cygwin\bin
- I was getting an incompatible version error for cygwin1.dll
*** fatal error - cygheap base mismatch detected
- Although some said a reboot will fix this, it did not.
- To resolve the version error, I copied the cygwin\bin directory from an older version of cygwin - version 1.7.30 worked
One could extend the number of features in git-bash by creating scripts and call them by defining them in the ~/.bash_profile file.
Example
If one would like to use the watch command, then this script could be added to the ~/.bash_profile:
ARGS="${@}" clear; while(true); do OUTPUT=`$ARGS` clear echo -e "${OUTPUT[@]}" done
and wrap it inside a function:
watch() { ARGS="${@}" clear; while(true); do OUTPUT=`$ARGS` clear echo -e "${OUTPUT[@]}" done
}As soon as one saves the file and runs source ~/.bash_profile then one should be able to watch the output of commands.
The above instructions are slightly outdated. Here is what recently worked for me. Use linux to download and extract necessary files:
sudo apt-get install zstd # download unpack tool
# get rsync and necessary libraries
wget
wget
wget
# unpack
tar -I zstd -xvf rsync-3.2.2-1-x86_64.pkg.tar.zst
tar -I zstd -xvf libzstd-1.5.0-1-x86_64.pkg.tar.zst
tar -I zstd -xvf libxxhash-0.7.4-1-x86_64.pkg.tar.zstnow copy everything to Windows...
for example MinGW/bin or Git/usr as explained above
To get rsync for Windows 10, this guide the only one worked for me
Steps in summary:
Download “mingw-get-setup.exe” from the MinGW SourceForge Project Site ().
Run the “mingw-get-setup.exe” and click the “Install” button. Then, navigate the left side options and select “MSYS”. Then locate and select only the “msys-rsync” bin package. Then, from the "Installation" drop down menu select “Apply Changes”.
Copy the following four files from the MinGW msys bin folder “C:\MinGW\msys\1.0\bin” to the Git bin folder “C:\Program Files (x86)\Git\bin”
msys-iconv-2.dll
msys-intl-8.dll
msys-popt-0.dll
rsync.exethen in Git Bash, run the following 2 commands:
echo '/c/MinGW/msys/1.0/bin/rsync "$@"' >/usr/bin/rsync
chmod +x /usr/bin/rsyncin Git Bash, run below command to check rsync is working:
rsync --version- (Optional) Delete entire C:/MinGW folder