I know how to clone a git repository to my system, using git clone. I cloned a repository using that command:

git clone https://github.com/<user name>/<repository name>

But when I tried to clone that repository again, which have been changed recently, I got this error message:

fatal: destination path '<repository name>' already exists and is not an empty directory.
  • 3
    git clone is for creating copy of that repository on your system. You want to update that repository with new changes ? – Sergiy Kolodyazhnyy Jul 24 '16 at 4:25

This is because cloning is used for creating the directory, setting it up for use with git, and copying the files into it. Since you already have files in that directory, it could be unwise to replace something in it that you might have put hours of work into, so it won't allow that.

You have two options:

Updating to the latest files

cd repository-name
git pull

Restarting from scratch

rm -rf repository-name
git clone https://github.com/username/repository-name
| improve this answer | |

Running git clone https://github.com/<user name>/<repository name> clones the repository into a local directory that is also named <repository name>. Running the same command again gives the error you saw because there is already a non-empty directory named <repository name>.

To proceed, you have two options:

  1. You can clone the repository into a different directory, which we call <different name>:

    git clone https://github.com/<user name>/<repository name> <different name>
  2. You can update the master branch of the cloned repository by running:

    git fetch origin  # fetch updates from origin remote
    git merge origin/master

    Alternatively, you can combine the two commands above into one:

    git pull origin master
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.