As a means to a backup, I push a folder structure to a GIT repository by committing new changes every once in a while. In this case, it's most parts of my Linux user's $HOME folder. As the backup also includes local folders of various applications (such as mailing client, browsers, ...), naturally, even seconds after a recent git-push there is a whole bunch of new and uncommitted changes.
As it happens, I accidentally destroyed my ~/.git/
folder (overwrote it with a ~/.git/
folder from another repository, so it's really gone). I'd like to recover it by sort-of-cloning the GIT history from the remote and retain all files' connection to their repository counter-part, yet don't want the local files overwritten by git-clone or git-pull. I tried to recover the .git/
folder by following this answer, using the git fetch
then git reset
version. All four commands finished without errors. However, as far as my local repository is concerned, I get stuck in kind of a limbo:
git branch -av
shows the correct remote master with the correct last commit there - but only that; there is no local branch/master listed.git status
shows:On branch master Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) [...]
The local files changed since the last commit and git-push do not get listed.
git log
shows:fatal: your current branch 'master' does not have any commits yet
I tried stashing local changes in order to git-pull and re-apply the stash; however,
git stash save
results in:fatal: bad revision 'HEAD' fatal: bad revision 'HEAD' fatal: Needed a single revision You do not have the initial commit yet
git checkout master
aborts with:error: The following untracked working tree files would be overwritten by checkout: [...] [... looooong list of files and folders ...] [...] Please move or remove them before you can switch branches. Aborting
git rev-parse --abbrev-ref HEAD
results in "HEAD
" – it should output a branch name or "master
" if everything was alright (I use this command to have the current branch name displayed in bash's prompt).
Can someone point me into a helpful direction as to how to "recover" the local repository and all file references without overwriting (uncommitted) changes? What seems to be missing in the answer from the other topic?