How to branch from deleted branch in git?

Member

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

How to branch from deleted branch in git?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by denis , 10 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>


Related Threads:

How to create a new branch in Git?
How to pull from master branch with git?
How to rebase git branch on master?
How to reset to the main branch in git?
How to revert git branch with all commits?
How to delete a folder from a git branch?