7

I am working on an Xcode project with source control. I messed up so I deleted the project from my laptop, and downloaded (ZIP) my own project which I pushed to GitHub earlier. But now this cloned project is not a git repository (or any of the parent directories): .git

Question: How do I reconnect my project to my existing GitHub repository?

Nick Volynkin
  • 14,023
  • 6
  • 43
  • 67
abacaba
  • 133
  • 1
  • 2
  • 9

2 Answers2

6

The easiest is to:

  • clone your GitHub project
  • cd in that local clone
  • do a git --work-tree=/path/to/unzip/project diff to check if your zip has any differences with the version cloned from git hub: if it does, git add and commit. (and by that use git --work-tree=/path/to/unzip/project add -A . and then a simple git commit, to record the differences from the zip version of the project and the git cloned one)
  • resume working with the local clone (which is a git repo)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    is the syntax really `git --work-tree='...' diff`, not `git diff --work-tree='...' ` ? – Nick Volynkin May 21 '15 at 05:46
  • 1
    @NickVolynkin yes, this isn't a parameter for `diff`, it is a parameter for `git` itself, in order to consider a different path as the current working tree. – VonC May 21 '15 at 05:49
  • 1
    @NickVolynkin you also have the `--git-dir` option. see http://stackoverflow.com/a/20115526/6309. – VonC May 21 '15 at 05:50
  • 1
    Oh, understood. Now for "git add and commit". What to add if the repo was just cloned? Files should be copied to the local clone. – Nick Volynkin May 21 '15 at 05:54
  • 1
    @NickVolynkin the `git add` would use `git --work-tree add` in order to add the content from the zip project to the git repo. I have edited my answer. – VonC May 21 '15 at 05:57
  • @VonC (1) Is a _work-tree_ a _branch_ or a _repo_? (2) Does _/path/to/unzip/project_ mean _https://github.com/username/repo.git_ ? – abacaba May 22 '15 at 04:16
  • 1
    @abacaba (1) work-tree is a repository state: see http://stackoverflow.com/a/30206960/6309. Here it tells git to consider a folder a being the working tree for the current git repo. So (2): `/path/to/unzip/project` is *not* a git repo: it is a backup of the project with their files (no git information in it). But the `--work-tree` allows git to consider those files as if they were for the current git repo that you just cloned. – VonC May 22 '15 at 07:01
6

Another option is to clone the git repository somewhere, and then copy the .git directory from there in to your project folder.

This folder will then become a git repository, and you can do git status and all the usual commands to do what you need to do.

There are probably some caveats, but it worked well for me in a situation where moving the project folder would have been difficult.

cedd
  • 1,741
  • 1
  • 21
  • 34