How to restore a deleted branch

'How Do I...' and 'How to...' Guide to Stash

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

There are three known ways to restore a deleted branch

1. Being the easiest is where if anyone has a local copy of the repository, that person can just push into Stash

2. If you have a backup of your repository, you could try to restore the entire repository back to $STASH_HOME directory

3. Using Git: 

- First, on your local repository, perform git reflog. This will list down all previous HEADs. Find the latest commit hash for the branch that you have deleted.
- Once you have the commit hash, perform git reset --hard <commit>. This will revert the HEAD back to the latest commit on the branch
- Recreate the branch again and checkout to that new branch git checkout -b <branchname>
- Then push the branch, git push origin <branchname>

(warning) Please take a *full backup* before performing this

Last modified on May 25, 2015

Was this helpful?

Provide feedback about this article
Powered by Confluence and Scroll Viewport.