0

I need to clone a repo that starts from /var to my local (Linux) machine's /var.

BitBucket repo: /var/...

I need to clone to my machine's /var

Since my local directory /var has other files, will cloning the repo locally to /var remove my already existing files and folders? If so, how could this handled carefully?

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
ooo
  • 673
  • 3
  • 16

1 Answers1

1

Git will not allow you to clone directly into a non-empty folder, which is for your benefit, especially if you want the safe approach.

The safe way to do this is to clone the repo normally, into wherever you normally clone your repos, like /home/myusername/myrepos or whatever. Then simply copy the files you want into /var. If you want, you can set up symlinks to point from under /var to the files in your repository.

I would not, under any circumstances, recommend removing /var and symlinking it to your repo (or deleting it and cloning over it). /var/ is relied on by many processes on your system. Messing with it like that will cause you problems, pretty much guaranteed.

Another alternative is to set up /var as a git repo. This will only be possible if your repository is set up with the contents of /var, not the actual folder itself. If /var is in your repo, you will need to clone to /, and I really don't think you should do that.

I do not recommend this approach either. That being said, here is a similar question: How do I clone into a non-empty directory?. The answer relevant to you recommends

cd /var
git init
git remote add origin YOUR_REMOTE_URL
git fetch
git reset origin/master
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264