How to View Deleted Branches in GitHub
Accidentally deleted a branch on GitHub and now you can't access its content? Don't panic, you can still view deleted branches. GitHub retains deleted branches' metadata, allowing you to see the branch's details, commit history, and even check out the code if necessary.
Before we dive in, ensure you're logged into your GitHub account and familiar with basic Git commands. Let's walk through how to view deleted branches on GitHub using the platform's interface and Git command line.
Viewing Deleted Branches on GitHub's Web Interface
GitHub's web interface provides an easy way to view deleted branches, although you can't see the code directly.
First, navigate to your repository's page. Then, follow these steps:
Using the Branch Drop-down Menu
1. Click on the branch drop-down menu, typically labeled "main" or "master".
2. You'll see a list of existing and deleted branches. Click on the branch name to see its commit history and other details.
Using the 'Deleted Branches' Tab
1. Click on the 'Branches' tab in your repository.
2. Switch to the 'Deleted Branches' tab. Here, you can see and interact with deleted branches, although you can't view the code directly.
Viewing Deleted Branches Using Git Command Line
For more detailed information, use Git's command-line interface. You can view deleted branches, their commit history, and even retrieve the code.
First, ensure you have Git installed and your repository cloned on your local machine. Then, follow these steps:
Viewing Deleted Branches & Commit History
1. In your terminal, navigate to your local repository.
2. Run `git branch --merged` to list all merged branches (including deleted ones) and `git branch --no-merged` to list unmerged branches.
Retrieving Deleted Branch's Code
1. To retrieve the deleted branch's code, use `git checkout -b
2. Entertainment your code carefully, as the command will overwrite local changes and you might lose work. Backup your progress before attempting recovery.
Now that you know how to view and retrieve deleted branches, it's essential to promote a culture of careful branch management to prevent accidental deletions. Regular backups and usage of Git's robust version control features can help maintain a safe and productive development environment.