I had the same error because I was using proxy. As the answer is given but in case you are using proxy then please set your proxy first using these commands:
git config --global http.proxy http://proxy_username:proxy_password@proxy_ip:port
git config --global https.proxy https://proxy_username:proxy_password@proxy_ip:port