Here is the initial situation:
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.
c:\repositories\myproject
git --git-dir=myproject config core.bare true
commandIt 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.
Another option is to provide the . character, thereby restoring all files in the current directory. Removes the file from the Staging Area, but leaves its actual modifications untouched. By default, the git restore command will discard any local, uncommitted changes in the corresponding files and thereby restore their last committed state.
Practically speaking everything in the repository apart from .git is a part of working tree. To create a bare repository, navigate to the chosen directory in bash (for linux users) or command prompt (for windows users) and type: The file structure of the bare repository should look like this:
It stores the hashes of commits made in the branches and a file where the hash of the latest commit is stored. As you can see, the .git folder contains all the required files for tracking the project folder. The default repository is always used for local repositories. What is a bare repository?
The only possible operations on the Bare Repository are Pushing or Cloning. A bare repository is linked with a local repository, hence the files in .git of local repo should match with the files in the bare repo. First, create a bare repository (See section for the code snippet). Cloning into 'BareRepo'...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With