How can I delete (or merge) a local Git branch that I'm currently on?

I'm pretty new to using git, and I use it to contribute to the AOKP Android ROM. I've successfully created a few branches, modified the code, and uploaded the commits that have gotten merged on the remote end. But in my local repository, those branches are still showing up (even though they show up as having no changes). The problem is that when I created those branches, I did so right from the subfolder that needed to be modified, so I don't have any "higher" branches to go to. And because of that, I can't delete those branches -- git tels me error: Cannot delete the branch 'MyMods' which you are currently on.

So what can I do to get rid of those branches?


Checkout a different branch first, before deleting it:

git checkout master
git branch -d MyMods

Also, branches have nothing to do with folders. Git always tracks the whole repository at once, with all its folders and files. A branch is nothing else than a pointer to a single commit, or snapshot, in the history of the repository.

Yes just checkout another branch(maybe master) and then:

git checkout master
git branch -d thebran

If the branch you cannot delete is a worktree then you may need to delete that worktree first:

rm -r MyMods
git worktree list    # shows MyMods
git worktree prune
git worktree list    # doesn't show MyMods
git branch -d MyMods

But in my local repository, those branches are still showing up (even though they show up as having no changes).

Branches will show up in your local repo unless you delete them. They don't disappear when you push them.

The answers above tell you how to delete a branch. However, I would add that using the -D option is a bit more powerful. This option deletes the branch regardless of its (un)merged status:

git branch -D branchName

It's the atomic bomb of branch deletion. Use with care.

Need Your Help

Create NSString by repeating another string a given number of times

objective-c cocoa string

This should be easy, but I'm having a hard time finding the easiest solution.

Design patterns used in symfony2

design-patterns symfony doctrine-orm

In symfony2, the services using Singleton patterns. Doctrine uses Unit of work patterns. I wonder a lot of design patterns may be used in symfony2. I think it will be useful to have better understa...