I have solved the problem. The problem was occurring because of different home directories of Git bash and cygwin.
When I generated the ssh key in my cygwin terminal the key was added to cygwin's .ssh folder which was C:\cygwin\home\windows\.ssh
and when I ran the command ssh -T git@github.com
it authenticated me using the ssh key which was in cygwin's .ssh directory.
But when I ran the command git clone git@github.com:repo/repo.git
, the key in git bash's home directory was used which was in C:\Users\windows\.ssh
. I copied the key present in cygwin's .ssh folder into this folder and everything worked fine.
However the weird thing is the git clone git@github.com:repo/repo.git
command didn't threw any error but instead just hanged.