-1

I am in my current branch and I made some changes of the files existing in master. I want to delete this branch and discard all those changes. But the problem is that I am not able to delete current branch, so I need to move to another branch an only after this I am able to delete the target branch. But the problem is that all those changes are moving to another branch as well because they are not committed yet. Is there any way to delete the branch and get rid of those changes at the same time and without committing?

Liam
  • 27,717
  • 28
  • 128
  • 190
vitaliy4us
  • 483
  • 5
  • 21
  • 2
    Does this answer your question? [How to revert uncommitted changes including files and folders?](https://stackoverflow.com/questions/5807137/how-to-revert-uncommitted-changes-including-files-and-folders) – IMSoP Mar 11 '22 at 15:18
  • 3
    Branches are made of commits. Uncommitted changes aren't in any commit, so aren't part of any branch. – IMSoP Mar 11 '22 at 15:19
  • 1
    If they aren't committed, they aren't moving to any other branch; they exist *only* in your current working directory. The only thing Git can do with such changes is either commit them (or more precisely, add them to the index, from where they *can* be committed) or restore the file to how it looks in the current branch. It's up to you to initiate either of those actions. – chepner Mar 11 '22 at 15:20
  • 1
    You could stash the changes instead? – evolutionxbox Mar 11 '22 at 15:22

1 Answers1

1

I found the solution: you can move to any branch and discard any local changes with git checkout -f command which prevents you from any changes made in your current branch if they were not committed. Then you can delete your target branch with git branch -d existing_branch_name command.

vitaliy4us
  • 483
  • 5
  • 21