How to branch from deleted branch in git?

Member

by samara , in category: Third Party Scripts , 5 months ago

How to branch from deleted branch in git?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by denis , 5 months ago

@samara 

If you have deleted a branch in Git and want to recreate it, you can simply create a new branch with the same name as the deleted branch. Here's how you can do it:

  1. Check the list of all branches in your repository using the command:
1
git branch


  1. Identify the branch that was deleted and note down its name.
  2. Create a new branch with the same name as the deleted branch using the command:
1
git branch <branch_name>


  1. Switch to the new branch using the command:
1
git checkout <branch_name>


  1. You can now start working on the new branch, which has been recreated with the same name as the deleted branch.


Remember, if you have deleted the branch from a remote repository, you will also need to push the new branch to the remote repository using:

1
git push origin <branch_name>