2

Short version:

What is the correct way to restore a local Github backup, back onto Github, while preserving the commit history?

Long version:

So, a while back, I was working on a few private repositories on Github. I was going to take a break from working on them, so to save a few bucks (and avoid making the source public), I made sure my local branches were fully updated, and then deleted the repositories from Github. Now, I'm ready to restore those local files back to Github, this time as public instead of private. However, I'm running into problems actually getting the files back onto the server.

I've already created a bare repo with the same name on Github. Origin is set correctly, since the project has the same name (and URL) as before. It's a small personal project, so there is only one branch (master).

However, since my git status is up-to-date (preserved from when I made the backup), when I try to add -A / commit / push --all, nothing happens. Pulls from the new, blank remote repo don't seem to help.

I found a couple discussions on how to restore from local git backups, but they all assume that you're restoring onto your own server, and can run commands server-side. Obviously, this isn't the case with a Github-hosted repo.

Any help would be appreciated!

1 Answer 1

1

Did you create an initial commit to the github repo? Have you tried force with your push? If I am understanding your history correctly, then the local repo you have is not an ancestor of what exists on github presently, so you need to force the refs to update, which should fill in all the history for your github repo to match your local one.

 -f, --force Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. Also, when --force-with-lease option is used, the command refuses to update a remote ref whose current value does not match what is expected. 
Sign up to request clarification or add additional context in comments.

3 Comments

I just tried git push --all --force origin, which completed without errors, but my files did not appear in the remote repo. The remote repo is a recreation of the original repo in name and URL, but not in content (which is what I'm trying to restore now).
@hwbehrens Hm, I really would have expected that to work. I tried the scenario you described exactly on my machine and it worked perfectly. Whether or not git "thought" it was up-to-date with origin was inconsequential. The other thing to suggest at this point is to triple-check everything is going to the right place. I am hard-pressed so here is a why-the-hell-not: clone your new repo on github, force push it from your local copy, then push the now-updated clone back to github. TBH though, if the remotes are right, it shouldn't matter. If not, it must be github (not just vanilla git related).
Okay, I guess I just needed to be told to do some sanity checks. Turns out there is something severely wrong with the git installation itself on the terminal I was using. Switching to a different machine resolved all my problems. Thanks for the help!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.