Reputation: 1499
I have a remote project, let's say original project A, i forked this project Lets call this B.
I deliberately deleted a branch from B, how can i get this branch back? I used gitlab UI to delete the branch.
Is there any way to initialize my fork with the original repository, such as restore all the branches to the branches present in A?
I tried
git fetch upstream
git pull upstream branchname
I cant seem to get the branch back.
Upvotes: 1
Views: 2148
Reputation: 109005
A git branch is just a reference to a commit (with some extra semantics for commits to move the branch to reference the new commit).
So the only way to "recover" a deleted branch is to re-create it by specifying the commit:
git branch <name> <start>
Where start
can be a commit or other way to reference a commit.
Finding which commit is another matter and depends on the information you have. If you have the ref log on the (local) repository with the last commit to the branch that would likely be easiest. Otherwise you're down to looking for dangling references (git fsck --unreachable
).
Upvotes: 2