1

I have a non-version controlled directory containing a codebase. I have the same codebase in git.

How can I introduce git in that directory without changing any of the files. I'd like to see all differences as unstaged changes.

I suppose I can clone the git repo to another directory and move the .git subdirectory but I wonder if there are git commands to do this directly

carl verbiest
  • 1,113
  • 1
  • 15
  • 30

1 Answers1

2

Initialise a git repository in that folder, add and fetch the remote, and do a diff:

$ git init
$ git remote add origin ...
$ git fetch origin
$ git diff origin/master

(the last command assumes your default branch is master)

Paolo
  • 21,270
  • 6
  • 38
  • 69
  • 2
    You certainly can do this, but you probably want to create a `main` or `master` pointing to `origin/main` or `origin/master` and then do a `git read-tree` from that commit, after the `git fetch` and before the `git diff`. – torek Dec 10 '21 at 09:40
  • 1
    or, as an alternative to torek, run `git checkout -b someName; git reset origin/someName` – LeGEC Dec 10 '21 at 11:24