Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 623
user496854 Avatar asked Sep 26 '12 16:09

user496854


People also ask

How do I delete my local branch in git?

The command to delete a local git branch can take one of two forms: git branch –delete old-branch. git branch -d old-branch.

How do I delete a local branch in merge?

Deleting a branch LOCALLY Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet. The branch is now deleted locally.

What happens if I delete a local branch in git?

What Happens If I Delete a Git Branch? When you delete a branch in Git, you don't delete the commits themselves. That's right: The commits are still there, and you might be able to recover them.


2 Answers

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.

like image 139
poke Avatar answered Oct 19 '22 08:10

poke


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

git checkout master git branch -d thebran 
like image 40
slash28cu Avatar answered Oct 19 '22 07:10

slash28cu