How to delete a branch in Git

Sometimes Xcode gets confused with the intricacies of versioning. Frequently I find that I’m on a branch, everything is working fine, and for the life of me can’t merge it back into the Master branch. Often this happens because Xcode refuses NOT to make an change, such as update certain files I have already dealt with in the new branch.

That’s when the command line git tool can come in handy.

Suppose my new branch Mavericks is what I’d like to merge into master, but both Xcode and GitHub hang when trying to do so, citing “unrelolvable conflicts” and weird error messages. Rather than trying to understand them, it’s probably easier to just DELETE master and create a new copy from my Mavericks branch. Let’s do this.

First display what we have – cd into your working directory first, then issue

OK, we’re on the Mavericks branch, and master also exists. Let’s delete master:

Done and dusted – master is history. Let’s create a copy and call it master, then check it out:

Nice – looks like we’re all set here. You can also combine the “branch + checkout” command by typing “git checkout -b master”

Back in Xcode (and GitHub) everything seems fine too.

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.