I have a git repository. It has A B C D E ... commits. Now I want to checkout D as a new branch named Dbranch. So I excute:git checkout D -b Dbranch
. And now I want to delete this branch. Firstly I need to switch to master branch , and then use git branch -d Dbranch
to delete it. But when I excute git checkout master
, it gives me the error.
error: The following untracked working tree files would be overwritten by checkout:
source/a/foo.c
...... (too many lines)
Please move or remove them before you can switch branches.
Aborting
How to delete the Dbranch?
Try git checkout -f master
.
-f
or --force
Source: https://www.kernel.org/pub/software/scm/git/docs/git-checkout.html
When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.
When checking out paths from the index, do not fail upon unmerged entries; instead, unmerged entries are ignored.