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:
Now, I have some questions:
In the top right corner of GitHub.com, click your profile photo, then click Your organizations. Next to the organization, click Settings. In the left sidebar, click Deleted repositories. Next to the repository you want to restore, click Restore.
Yes, it is possible. By using git reflog find the SHA1 for the commit at the tip of your deleted branch, then just git checkout [sha]. And once you're at that commit, you can just git checkout -b [branchname] to recreate the branch from there.
If you have deleted the file and already committed the changes, you need to use the ` git checkout` command to restore the file. First, you need to find out the checksum of the commit that deleted the file, and then check out the file from the previous commit.
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.
Since your remote was deleted you don't have any origin yet so you will have to checkout the "remote" branches locally and assign them the original name and than push all the branches to the remote.
If you dont want the local branches simply push the ones you need.
Here is a scrip which im using to checkout all branches and than push them to the new remote
#!/bin/bash
# add the new origin
git remote add origin2 <url>
# loop over all the original branches and set the new remote as the new track origin
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
git branch --track ${branch#remotes/origin2/} $branch
done
# now push all branches and tags
git push origin2 --all
git push origin2 --tags
git branch -a
get a list of all the local branches
| grep remotes
The branch names are : 'remotes/origin/' so this will remove the remotes from the branch names
| grep -v HEAD | grep -v master
remove the master (current branch) and HEAD which is an alias to the latest commit
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