Search code examples
gitgitlabrecoverygitlab-ce

how to recover from a Git remote repository deleted


We had a Gitlab CE on a vm in our server.
There were 3 people working on a single repository on this Gitlab server.
This Gitlab CE vm has been deleted accidentally! These 3 people still have their local repositories with a lot of branches.
Our branching strategy was like this:
We had a Master branch and some feature branches per user.
users used to:

  • pull master from remote,
  • make a branch from it,
  • make changes,
  • push to master again (via merge requests)

Now, I have some questions:

  1. Is there any way-strategy to recreate-rebuild remote repo from local ones?
  2. If not, what should I do to create another remote repo and merge all commits to it?

Solution

    • Create an empty repo in GitLab/BitBucket/GitHub.

    • Add a new remote (say, another) in your current repo with the URL of the new repo. Then push your master branch commits/changes to another repo's master branch.

      $ git remote add another <new-repo-url>
      $ git remote -v                 # see if the remote is added correctly 
      $ git checkout master
      
      $ git push another master       # push the changes to another/master
      
    • If you need features of another branch (say, feature) then simply checkout to the feature branch and push the changes to another repo's feature branch.

      $ git checkout feature
      $ git push another feature      # push changes to 'another' repo's 'feature' branch
      
    • Push all the branches and tags to another repo.

      $ git push --all --tags another
      

    N.B. Here, another represents your new repo's URL.