How can I link an existing directory to an existing git repo

Viewed 16184

I have a folder foo, without any git integration

/foo
    file1.txt
    file2.txt

and my own repo, which already has several branches, including master

https://my-fake-repo

I would like to link foo to the master at https://my-fake-repo, such that if I then ran 'git diff', I would see the differences between /foo and https://my-fake-repo's master.

I want the equivalent of checking out https://my-fake-repo, deleting the contents, and pasting the files from /foo into it. I was hoping I could do this with just some Git commands, but i'm not familiar enough with Git and my research is failing. I attempted to do something like:

cd /foo
git init
git remote add origin https://my-fake-repo
git branch master --set-upstream-to origin/master

but master doesn't exist yet, so it doesn't work...

2 Answers

Not sure how you got into this use case. But another way is to simply clone the remote to a new folder, /foo2, and then copy /foo over to /foo2. Then you can see the changes if any, and proceed normally to discard/commit the differences.

Related