1

A branch on our cloud repository was deleted. I still have this branch in my local git repository. I want to restore this branch in the cloud repository.

Is this possible?

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
SixDegrees
  • 781
  • 1
  • 8
  • 19
  • 3
    Push the branch. – Maroun Aug 16 '20 at 18:58
  • It depends what you mean by restore. Is the branch in your local repository up to the same commit as the corresponding branch in the cloud repository? – matt Aug 16 '20 at 19:15
  • The branch in the cloud repository matched what I have, but it was deleted. – SixDegrees Aug 16 '20 at 19:42
  • Push the branch `git push origin ` – SwissCodeMen Aug 16 '20 at 21:41
  • Before I do that: a bit more poking around reveals that this branch was merged with the main branch in the cloud - but not in my local repo, where I haven't done a pull yet. If I push the unmerged branch from my repo, will it reappear in the cloud repo as a merged branch? Or will it reappear as a separate branch? I guess the former would be my hope, because the main branch now has those merged changes on it. – SixDegrees Aug 16 '20 at 22:25

3 Answers3

1

Below command directly changes the remote branch you mentioned

git push -f origin <previous_commit>:<branch_name>

Locally try below command

git reset --hard <previous_commit>

And now push the changes to remote

0

If I push the unmerged branch from my repo, will it reappear in the cloud repo as a merged branch? Or will it reappear as a separate branch?

As a separate branch.
But the remote repository already has those commits (that you are pushing) through its merge commit: a merge commit has two parent, the second one being the branch being merged.
All you will be pushing will be the branch name on the last commit of that branch.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Deleting a branch after it has been merged is correct behavior. You should not push and undo all of that. You should fetch and prune, and delete your local copy of the branch.

matt
  • 515,959
  • 87
  • 875
  • 1,141