Skip to content
Logo Theodo

Use git, ssh and npm on windows with Git Bash

Nicolas Ngô-Maï4 min read

If you are used to develop on Linux and you have to suddenly switch back to Windows for a particular project, it can be really painful to use native tools like putty or power shell to develop.
Don’t worry, there are plenty of solutions to make things right.
For example, you could work on a Linux virtual machine inside your Windows.
Another solution (the one I chose) is to use Git Bash.
This setup has several advantages:

We are going to configure and package nodejs/npm inside the Git Bash to share it with every developers of your new team.

Get the softwares

First, get the desired softwares and add these to C:\Applications\ (where you will have sufficient rights to execute them):

Git portable edition comes with Git Bash included.

You should now have a folder which looks like this :

├─ git
│  ├─ git_bash.exe
│  └─ etc
│     ├─ profile (edited)
│     └─ node_env.conf
└─ node
   ├─ node
   └─ npm

Configure your shell

In git Bash, a Linux like environement is simulated so you can access your Linux filesystem with Linux style paths.
For example, to print the content of C:\Applications\ you can type:

ls /c/Applications

Open git bash and type the following command:

export PATH=$PATH:/c/Applications/node

Type then node --version and npm --version to check that node and npm are available.
If not, check that you have the npm and node.exe files in C:\Applications\node.

To reproduce this configuration when launching your terminal, you can create a custom configuration file in C:\Applications\git\etc\node_env.conf :

# Include node PATH

Edit your etc/profile git bash file (Windows location: C:\Applications\git\etc\profile) and add the following line just before exporting the PATH:

source "etc/node_env.conf"

You should then be able to use npm and node out of the box!
For example, if you want to contribute to this planning burndown chart project:

git clone && cd planning-bdc
npm install
npm run watch

And here you go!

Use SSH in your shell

And now how about using SSH to connect to github?
Indeed, Git Bash comes with a lot of features from Linux like grep, find, sed, and even ssh and scp!
To create a SSH key:

ssh-keygen -t rsa -b 4096 -C ""

As in Linux, the key file location will be in ~/.ssh:

cat $HOME/.ssh/

Add it to Github and run:

git clone && cd planning-bdc
npm install
npm run watch

And here you go again!

Set up your proxies (optional)

If you get stuck when using git clone or npm install, you may be blocked by a proxy (which requires configuration as well). Find out what the address is following this process.

Add the following lines to your node_env.conf :

if [ -f "etc/node_env.var" ];
  source "etc/node_env.var"
  touch etc/node_env.var

  read -p "What is your proxy login? " PROXY_LOGIN
  echo "PROXY_LOGIN=\"${PROXY_LOGIN}\"" >> etc/node_env.var

  read -p "What is your proxy password? " PROXY_PASSWORD
  echo "PROXY_PASSWORD=\"${PROXY_PASSWORD}\"" >> etc/node_env.var

  echo "PROXY_ADDRESS=\"${PROXY_ADDRESS}\"" >> etc/node_env.var

  echo "PROXY_PORT=\"${PROXY_PORT}\"" >> etc/node_env.var

# Used for Node Terminal proxy (for packages as shipit)
# Npm proxy
npm config set proxy $HTTP_PROXY
npm config set https-proxy $HTTPS_PROXY
# Git proxy
git config --global http.proxy $HTTP_PROXY
git config --global https.proxy $HTTPS_PROXY

This piece of bash code will :

Be careful with your HTTPS proxy, it might have a different address / port than your http proxy

Start your Git Bash and you should be asked for the proxy variables. You should now be able to use git clone and npm install for your applications!

You can also use the integrated ssh client.

If you need to change the variables, destroy the node_env.var file and you will be asked for new values.


Now you got a configured and packaged Git Bash, you can adapt it to create your own environement!
Thanks for reading, don’t hesitate to leave feedback!

Liked this article?