Here are the commands I used from the master branch
git branch experiment
git checkout experiment
Then I made some changes to my files, commi
As Drew Taylor pointed out, branch deletion with -d only considers the current HEAD in determining if the branch is "fully merged". It will complain even if the branch is merged with some other branch. The error message could definitely be clearer in this regard... You can either checkout the merged branch before deleting, or just use git branch -D. The capital -D will override the check entirely.
I had this happen to me today, as I was merging my very first feature branch back into master. As some said in a thread elsewhere on SO, the trick was switching back to master before trying to delete the branch. Once in back in master, git was happy to delete the branch without any warnings.
Easiest Solution With Explanation (double checked solution) (faced the problem before)
Problem is:
1- I can't delete a branch
2- The terminal keep display a warning message that there are some commits that are not approved yet
3- knowing that I checked the master and branch and they are identical (up to date)
solution:
git checkout master
git merge branch_name
git checkout branch_name
git push
git checkout master
git branch -d branch_name
Explanation:
when your branch is connected to upstream remote branch (on Github, bitbucket or whatever), you need to merge (push) it into the master, and you need to push the new changes (commits) to the remote repo (Github, bitbucket or whatever) from the branch,
what I did in my code is that I switched to master, then merge the branch into it (to make sure they're identical on your local machine), then I switched to the branch again and pushed the updates or changes into the remote online repo using "git push".
after that, I switched to the master again, and tried to delete the branch, and the problem (warning message) disappeared, and the branch deleted successfully
I tried sehe's answer and it did not work.
To find the commits that have not been merged simply use:
git log feature-branch ^master --no-merges
I did not have the upstream branch on my local git. I had created a local branch from master, git checkout -b mybranch . I created a branch with bitbucket GUI on the upstream git and pushed my local branch (mybranch) to that upstream branch. Once I did a git fetch on my local git to retrieve the upstream branch, I could do a git branch -d mybranch.
I believe the flag --force
is what you are really looking for. Just use git branch -d --force <branch_name>
to delete the branch forcibly.