Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git cloning into current directory [duplicate]

Tags:

git

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

like image 361
cheese5505 Avatar asked May 31 '15 10:05

cheese5505


People also ask

How do I clone a git repository to a specific folder?

To clone git repository into a specific folder, you can use -C <path> parameter, e.g. Although it'll still create a whatever folder on top of it, so to clone the content of the repository into current directory, use the following syntax: cd /httpdocs git clone [email protected]:whatever .

What happens when you clone a git repository?

Cloning a repository pulls down a full copy of all the repository data that GitHub.com has at that point in time, including all versions of every file and folder for the project. You can push your changes to the remote repository on GitHub.com, or pull other people's changes from GitHub.com.

Can you git clone twice?

Simply clone your project's repo twice (or even more often). When your work on a feature branch is done, simply push that branch and check it out on your 2nd copy to run tests there. You can pick up a new story and work on that on your "main" project directory.


Video Answer


2 Answers

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>

like image 93
CodeWizard Avatar answered Sep 28 '22 22:09

CodeWizard


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 ./
like image 42
mainframer Avatar answered Sep 28 '22 21:09

mainframer