Search code examples
gitpycharmbranch

how to recover deleted branch after deletion from Pycharm


Have deleted the branch from Pycharm . I got a suboption as delete and accidentally I clicked it. The branch got deleted from the origin .Is there a way to recover the branch other than using git?


Solution

  • Don't run: git gc

    Run below commands in terminal at root of project.

    Find all dangling commits:

    git fsck --no-reflog
    Checking object directories: 100% (256/256), done.
    Checking objects: 100% (8459/8459), done.
    dangling commit 2e04e4159219dbd35f55a53fb0c6ae9c187f6b8e
    dangling commit 9db660c967e3b410b354c0024090a5d0bfabb614
    dangling commit dc6f48a17b749ad6a76ec1fe9434b8427487dbb6
    

    Checkout to commit to see if it was your last commit.

    git checkout 2e04e4159219dbd35f55a53fb0c6ae9c187f6b8e
    git log
    

    If found commit is right commit, then checkout your branch from it

    git checkout -b <YOUR BRANCH>
    

    Your branch is recovered.

    Thanks