I have an xcode project on my desktop in a directory that originally had a git repository with a tracking branch that tracked a remote branch on github. The remote branch has some 84 commits and is 2 commits ahead of the master branch of the project I'm adding features to. I changed the name of the folder/directory on my desktop. I'm not 100% sure if this is the reason why but when I go to git status
I get: fatal: Not a git repository (or any of the parent directories): .git
. My plan is to simply git Init, add the remote branch and create a new tracking branch and than commit locally to that branch and than push to the remote branch. However, I'm a git beginner and I'm not sure if this is the proper way to go about it. I'm very weary of losing any commit history or accidentally breaking something. Is the method I outlined a good way of rectifying this loss of the git repo?
Asked
Active
Viewed 5,740 times
1

Alexander Bollbach
- 649
- 6
- 20
-
Possible duplicate of [Does running git init twice initialize a repository or reinitialize an existing repo?](http://stackoverflow.com/questions/5149694/does-running-git-init-twice-initialize-a-repository-or-reinitialize-an-existing) – Sazzad Hissain Khan Jan 08 '16 at 04:31
-
check http://stackoverflow.com/questions/5149694/does-running-git-init-twice-initialize-a-repository-or-reinitialize-an-existing – Sazzad Hissain Khan Jan 08 '16 at 04:31
-
I think my question is slightly different. I have NO .git folder in this project folder. Therefore ALL of the commit history is on the remote branch. So what I want to do is commit all the changes I've made (since the .git repo was deleted somehow) on top of the up to date commit history for the remote branch. – Alexander Bollbach Jan 08 '16 at 04:54
2 Answers
0
If you have all your code updated in remote repo then your local .git is deleted. You don't need to re-init your local repo. Rather just clone it.
git clone remote_repo
If you don't have any commit in remote repo, Simply follow
git init
git add all_local_files
If you have updated remote repo than some commits made in local but not pushed and you lost .git. Simply clone remote. Add all files in a single commit
git clone
git add all_local_files

Sazzad Hissain Khan
- 37,929
- 33
- 189
- 256
0
Looks like you messed up your git repository, but not the code / contents.
One way to restore and keep local changes ( if any ) would be:
- Clone another copy of your repo from github.
- Copy all modified files to the new repo, omitting removed ones:
rsync -duztv /old/local/repo/ /new/local/repo
git status
to see what the situation is.

Zloj
- 2,235
- 2
- 18
- 28
-
one thing i'm trying to get straight is that a commit is essentially a record of the changes in files from one point in time to the next, right? So I have commit's 1-25 on this remote branch called REMOTE. At this point that is the only branch that exists. I clone the remote repo and get that branch locally? When I git status what will I see? Will it show me the differences between the current local status and commit 25? If so, should I just commit and push commit 26 to the remote repo branch: REMOTE? Also do i need to create a local branch? – Alexander Bollbach Jan 08 '16 at 06:12
-
@SubjectiveC this is the question worth a separate `question` or reading and understanding git. However, since you messed up your local repo and want to keep changes you've made there - a good solution is to clone a working copy some place else on the disk and move your local changes from first repo to that new one. Then type that status and see if it is what you need. If it is - commit and push. The remote branch that you want to push to exists, right? So the problem narrows down to the fact that you want to keep your hard-worked changes instead of discrading them. – Zloj Jan 08 '16 at 16:37
-
Restoring repo manually with `init` or other methods may be dangerous as you risk to make `git push --force` on some step. That operation can be almost deadly. – Zloj Jan 08 '16 at 16:38