Git Bash "If" AND "For" logic in same script seems to be incorrect
<p>I have a script that loops through all of my bitbucket repositories and it is supposed to clone it if it doesn't exist locally and pull it if it does. Lets say i dont have any of the directories needed. I can run the script below and everything works correctly. If i run the same script again, it is still hitting the first part of the if statement and saying "the destination already exists and is not an empty repository". Now lets say i get rid of the "!", it now hits the second part of the logic for everything. This isnt making sense to me. Im new to git bash so any help would be appreciated.  </p>

<pre><code>#!/bin/bash
#script to get all repositories under a user from bitbucket
#Usage: getAllRepos.sh [user]

curl -u user https://api.bitbucket.org/1.0/users/user &gt; repoinfo
for repo_name in $(grep -oE '\"slug\": "[^"]*"' repoinfo | cut -f4 -d\")
do
if [ ! -d "$repo_name" ];  then

git clone "git@bitbucket.org:user/$repo_name.git" "C:\\Users\\user\\.ssh\\$repo_name"

else 

git pull "git@bitbucket.org:user/$repo_name.git"

fi
done
</code></pre>

<p>I have updated the code to include corrections from the website recommended and it is still not working.</p>