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...
Drag and drop the file or folder you'd like to upload to your repository onto the file tree.
I want the equivalent of checking out https://my-fake-repo, deleting the contents, and pasting the files from /foo into it.
A simple way to achieve that is to pretend as if /foo
is the work tree of the repository, by doing this inside the local clone of my-fake-repo
:
GIT_WORK_TREE=/foo git diff
This will effectively compare the content of /foo
with the content of the repository.
Content that is in /foo
but not in the repo will be shown as added,
content that is not in /foo
but exists in the repo will be shown as deleted. And so on.
This trick will work with all other Git commands as well.
So be careful,
because if you run commands that modify the working tree (for example checkout
or reset
),
they will modify the content of /foo
.
But I'm wondering if this is really your ultimate way of working with /foo
and the Git repository.
You also mentioned "linking" to the Git repository.
The proper way to interact between repositories is by using remotes.
You could convert /foo
to a Git repository,
register my-fake-repo
as a remote,
and then use normal Git operations between the two repos,
without resulting to trickeries like at the top of this post.
cd /foo
git init
git add --all
git commit -m 'Add files'
git remote add origin https://my-fake-repo
git fetch origin
git diff origin/master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With