0

I have a Git repository and a local directory copied from it that is not a repository. The directory diverged from the repository awhile ago.

I want to:

  1. Make it a repository.
  2. Link it to the remote repository.
  3. See what changed and selectively commit local files and push them to the remote.

Essentially it is the same as cloning the remote and copying my directory over it.

Is there a graceful way without copying? I cannot copy because the local directory is large, and I would have exceeded quota.

I have found many answers like this: https://stackoverflow.com/a/45577839/11382675

git init
git add --all
git commit -m 'Add files'
git remote add origin https://...
git fetch origin
git diff origin/master

The difference is that I want to keep the new local files untracked, and so I cannot commit them.

I also attempted to do the following:

  1. Cloned the repository.
  2. Copied the .git from it into the directory.

But when I do git add -i I get all the files listed as unchanged:

...
 16993:    unchanged        +0/-0 shared/PHPMailer/language/phpmailer.lang-sk.php
 16994:    unchanged        +0/-0 shared/PHPMailer/language/phpmailer.lang-sr.php
 16995:    unchanged        +0/-0 shared/PHPMailer/language/phpmailer.lang-tr.php
 16996:    unchanged        +0/-0 shared/PHPMailer/language/phpmailer.lang-uk.php
 16997:    unchanged        +0/-0 shared/PHPMailer/language/phpmailer.lang-vi.php
...

Since we are here I wonder why I get this output?

Alexey Inkin
  • 1,853
  • 1
  • 12
  • 32

1 Answers1

0

All files are shown as modified because they have different permissions, as pointed out here.

This command configures git to ignore the permissions:

git config core.filemode false

With that, copying the .git directory from the clone does the job.

Alexey Inkin
  • 1,853
  • 1
  • 12
  • 32