Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git files in removed branch still exists in my project directory

In my rails project i use git to manage my code. I delete a branch with git like this :

git branch -D "my-branch-with-errors"

but files added with this removed branch still exists in my project. what's the problem here and how can i solve this issue. thank you

like image 249
medBouzid Avatar asked Dec 15 '25 16:12

medBouzid


1 Answers

If you create new files in a Git repository but don't git commit them, Git doesn't manage them. This means that changing branches, changing commits, or reverting changes does not affect those new files. You can either manually delete those new files, or run git clean, which deletes unversioned files.

To delete the files you added, run

git clean -n

This will let you see which files Git will delete before your remove them so that you can be sure it won't affect any files you want to keep. Once you are sure that it will only affect files you want to get rid of, run

git clean -f -d

For more information, see this question.

like image 199
Kevin Avatar answered Dec 17 '25 13:12

Kevin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!