Reputation: 135
I created a new branch using git checkout -b new_branch_name
.
I haven't run git add
or git commit
yet.
I want to get rid of this branch completely, including any new files, and switch back to master. How do I do this?
Upvotes: 1
Views: 6297
Reputation: 1799
A branch is just a pointer to a commit:
$ cat .git/refs/heads/master
6eef8fb523469b12abc530cd105c7b92a4a0a76a
So, when you delete a branch with git branch -D branch_name
, it just deletes the file branch_name
in .git/refs/heads
, it doesn't touch the working tree (i.e. the actual c or java or python or whatever files you're using git to track).
To clean up any untracked files after deleting your branch, just use:
git clean -df
The -d
flag will also remove untracked directories. The -f
flag forces the clean in case the config option clean.requireForce
is set to true. You can add the -i
flag if you want to review the work interactively.
If you have any tracked files with changes after deleting your branch, you can reset those with:
git reset --hard
Upvotes: 2
Reputation: 4853
Use the following to switch back to master:
git checkout master
Use the following to delete the branch you created:
git branch -D new_branch_name
Upvotes: 9