Question

Here is the initial situation:

  • A bare Git repository on a remote server
  • A development Git repository on a local machine

Then the remote server crashes.

I keep committing changes into my local repository but I cannot push them until we fix the server. In a day or so it becomes apparent that the server cannot be recovered due to a hardware problem, so the remote repository is lost. Meanwhile, I had already made several commits into my local repository.

Now I am trying to restore the repository on the server.

  1. I copy the files from my local .git folder to c:\repositories\myproject
  2. I run git --git-dir=myproject config core.bare true command

It looks good, however, the problem now is that I have two branches in the bare repository, one is master (server branch on the moment of crash), another is remote/origin (the newer branch with my local commits).

So essentially I would like to push the outstanding commits to master and remove the remote/origin branch at all as it is not needed in the bare repository.

How do I do that?

Feel free to share a better way to accomplish such task.

Was it helpful?

Solution

One way would be to re-initialize the remote repository completely cleanly and then do a push from local.

On the server, in the directory where the bare repository should live, do

 git init --bare

On the client (local repo), set the new origin if it has changed, and push to the server, and set up tracking again.

git remote set-url origin <Remote_URL>
git push origin master
git branch --set-upstream-to=origin/master master
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top