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

0

3 Answers 3

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>

Sign up to request clarification or add additional context in comments.

4 Comments

I need to wait until the server guy can open the ports for SSH but i'll let you know if it works!
If you need to open ssh you will need to generate ssh keys and add them to your server. ssh-keygen -t rsa -C "[email protected]" and then place the public key on your server
I have a public key set up, but our git server is currently set up to only accept local SSH connections.
step2: you need to add git remote add origin <remote_url>
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 ./ 

Comments

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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.