How do you restoreBranches that You Deleted from the /branches screen in a repo in Github? #55884
-
Select Topic AreaQuestion BodyHello - I deleted a branch from within the "branches" web page in my repo on the Github webpage. The branch was called "add_new_databricks_jobs" - I cannot find documentation for how you can recover a branch specifically when you deleted it this way. Can you help please? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 20 replies
-
When you delete a branch, you are only deleting a reference to the commit at the tip of that branch. The commits themselves are still present in the repository. Here's a step-by-step guide on how to recover a deleted branch. This assumes that you have at least a clone of the repository with the commits which were in the branch: Open a terminal and change to the directory where your project is located. Use the following command to look at all commits across all branches, along with their comments:
This will give you a long list of every commit made in every branch in your repository. Look for the commit that was the head of the deleted branch. This will be the last commit that was made to the branch. You should recognize it by the commit message. Once you find it, make a note of the commit hash (the long string of numbers and letters next to each commit). Once you have the hash of the commit that was at the tip of the branch, use the following command to create a new branch with this commit as the head:
Replace with the actual hash of the commit. This command will create a new branch with the same name as the deleted one and move you into it. If you want to push this branch to the remote repository, use the following command:
That's it! Your branch should be restored. Please note that these instructions will only work if the commits that were on the branch still exist in your local repository. If you have garbage collected your repo (git gc), or if the branch was only present in a different clone of the repository that you do not have access to, then this process will not work. In that case, you would need to find a copy of that branch in a different clone of the repository. Also, be aware that if you had any uncommitted changes in your working directory or index when the branch was deleted, those changes would not have been part of any commit, and thus will not be recoverable using this method. |
Beta Was this translation helpful? Give feedback.
-
hello, the easiest solution is to Open the repository in GitHub where the branch was deleted.
|
Beta Was this translation helpful? Give feedback.
-
Goto all branched and click activity of any one branch Then click activity from all branched then click ... to restore deleted branch |
Beta Was this translation helpful? Give feedback.
-
To recover a deleted branch on GitHub, you can try the following steps:
|
Beta Was this translation helpful? Give feedback.
Hello,