How to remove a branch but keep the orphaned with the same name?

I have a Python project where the documentation is in an orphaned gh-pages branch which I created by following this tutorial. There is a doc/build/html folder in the project where the docs get compiled and where the gh-pages branch is checked out.

Now, I accidentally executed the git checkout gh-pages command in the project root, which created a new gh-pages branch and now it seems that I have two of them. One orphaned and one normal. Is it so?

  • Recommended workflow for multiple modules (themes)
  • `git rebase` entire branch-tree
  • Performing merge of two very different branches complicated by need to fast-forward merge-commit
  • Amend a past commit from a previously merged branch, while keeping branch history
  • TFS — Sustainability of Cascading Branches
  • Are cherry pick merges appropriate in this scheme?
  • How do I remove the normal gh-pages branch but keep the orphaned one?

  • TortoiseGit - Revert?
  • Git checkout to commit number N
  • Why would git log/status return no output?
  • Git with two remote repos, one git, one svn
  • Git pull suddenly stopped working, troubleshooting “Repository not found”
  • Recommended workflow for public and private forks of a public GIT-SVN-created repo
  • One Solution collect form web for “How to remove a branch but keep the orphaned with the same name?”

    What happened is you created a local branch called gh-pages. It has nothing to do with the the gh-pages branch that exists on your GitHub account, it’s just a branch with the same name. (And this is why you get a conflict when you try to push this to GitHub: the two branches have nothing to do with each other.)

    You can delete your local branch safely with:

    git branch -d gh-pages
    

    This command is always safe, because it will only delete a branch if all the commits in it exist in another local branch. You cannot accidentally delete an orphaned branch with it. (Don’t confuse it with -D, that’s the one that will delete branches even if it has unmerged unique commits.)

    Btw, maybe this is the command you were looking for in the first place:

    git checkout --track origin/gh-pages
    # or in older versions of Git:
    #git checkout -b gh-pages origin/gh-pages
    

    This creates a local branch called gh-pages from the gh-pages branch at your origin (= GitHub). What you actually did was you created a local branch called gh-pages based on your current branch, probably master, NOT based on a remote branch.

    Git Baby is a git and github fan, let's start git clone.