how to delete a branch from a repo in sourcetree with only 1 branch?

I have SourceTree installed on my local environment. I’m working within a shared collection of git repos for at an enterprise. Looks like the admin created a new repo RepoY and we previously only had 1 repo (RepoX). I accidentally created BranchZ in RepoY and I need to delete it.

I selected BranchZ through SourceTree under RepoY, right-clicked and I was able to “Remove” it but now it displays with a red minus sign to the left. I tried to “Delete” the branch but SourceTree returns the following error: “error: Cannot delete the branch ‘BranchZ’ which you are currently on.”

  • Is there a way to get a visual diff on two branches in SourceTree?
  • Lost changes in git merge after marking a separate file as “resolved”
  • Custom diff by textconv in SourceTree
  • How to add icon to my repository?
  • Cant commit after starting a merge in Sourcetree
  • How to set up your avatar in
  • I’m not able to switch branches within the repo because BranchZ is the only branch in the repo. If I double-click a different repo in SourceTree then I can only delete RepoY but not BranchZ within RepoY. Is there a way to do what I’m trying to do through SourceTree or is this a limitation of SourceTree?

  • Git: forcing tests before pushing to local or remote master
  • Git - A Way of Removing / Reversing a Commit
  • Is there a Windows version controll client that supports Git, Mercurial, and Subversion (all in one)
  • git change default branch (gitolite)
  • How can I save my secret keys and password securely in my version control system?
  • How should I proceed building an application after cloning a boilerplate?
  • 2 Solutions collect form web for “how to delete a branch from a repo in sourcetree with only 1 branch?”

    When you create a git repository using git init, master branch will be created by default. I think in your case master branch may be deleted by some mistake, or you accidently renamed it. So, in this case, what you can do from SourceTree is,

    1. Create a branch called master
    2. Checkout master branch
    3. Delete BranchZ branch

    Or from command line,

    cd <repo_dir>
    git branch master
    git checkout master
    git branch -d BranchZ

    You are not allow to delete the branch which you are on, firstly you have checkout to another branch since it is the only branch you can just simply checkout master branch(every repo has master branch if it wasn’t deleted). Then you are able to delete but be sure you are in correct repo.

    git checkout master
    git git push origin :<branchName> (it deletes local and remote branch in case of you already pushed commits)
    Git Baby is a git and github fan, let's start git clone.