16

I am trying to clone a repository into my current directory. However, when I clone it with this command:

git clone REPOURL .

it says:

fatal: destination path '.' already exists and is not an empty directory.

The folders that I am cloning into already exist and I just want to add files that I have in the git repo.

Is there any way I can do this?

Thanks

cheese5505
  • 962
  • 5
  • 14
  • 30

3 Answers3

35

You don't need to clone the repository, you need to add remote and then add the files to the repository.

git init
git remote add origin <remote_url>
git fetch --all --prune
git checkout master
git add -A .
git commit -m "Adding my files..."

In details:

You already have a remote repository and you want to add files to this repository.

  1. First you have to "tell" git that the current directory is a git repository
    git init

  2. Then you need to tell git what is the url of the remote repository
    git remote add origin <remote_url>

  3. Now you will need to grab the content of the remote repository (all the content - branches, tags etc) git fetch --all --prune

  4. Check out the desired branch (master in this example)
    git checkout <branch>

  5. Add the new files to the current <branch> git add -A .

  6. Commit your changes git commit

  7. Upload your changes back to the remote repository git push origin <branch>

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
3

You can use the git clone --bare origin_url syntax to just clone files(not repo foder).

Try:

mkdir tmp
cd tmp
git clone --bare origin_url ./
mainframer
  • 20,411
  • 12
  • 49
  • 68
1

Edit: brain not working forgot about "."

What you are doing is asking git to clone the repo files into the current folder but the folder must be completely empty including no .git or you will get the error.

If you checkout this question it may help you achieve what you are trying to do Clone contents of a GitHub repository (without the folder itself)

Community
  • 1
  • 1
Astabh
  • 59
  • 2
  • 11