A year ago I opened a Bitbucket account and used it to follow versions of a local folder (on my personal laptop).
Since then my laptop "died" and I bought a new one. My files were backed up on a Mega cloud, so they recovered successfully. Though, the .git file wasn't recovered. Now I want to connect the updated local repository to the old outdated Bitbucket repository.
How can I do it without deleting the current local updates?
Appreciate your help!
It's odd to me that the
.gitdirectory would not have been restored in your backup. From a perspective outside git, the files in this directory are no different from any other files. I would want to be sure I understood the reason for that before deciding what to do next.But since you refer to the "updated local repository", I'll assume you've already taken steps to create a new git repo at the local path, regardless of what was going on before[1]. In that case, you presumably have something like this:
I'm assuming that the first commit in your new repo is a newer state of the directory, compared to the last commit that was saved in BitBucket.
So the first thing to do is to configure the bitbucket repository as a remote
where the URL is the same one you would use for cloning. Then
and you have locally
Next you need to
re-parentEontoD. See thegit filter-branchdocs (https://git-scm.com/docs/git-filter-branch), specifically relating to the--parent-filteroption. There are several examples showing different ways to accomplish this task.[1] If I'm misreading your statement, and you haven't yet recreated the local repo, that's actually simpler, because that means there's no local history to be grafted in. In that case, you could do something like
Then stage and commit your current state. It's a bit of a kludge, transplanting the
.gitfolder like that; but it seems to work in my tests and I know of no reason it should fail.