I'm getting an error when I tried to delete my branch

I got an email saying that my changes were merged and a short congratulations message. There was a button that said something like “Delete branch” which I clicked. My branch name was/is fix/catphotoapp-typos.

In VS Code right now I tried this git command and got an error message:

git branch -d fix/catphotoapp-typos
error: Cannot delete branch 'fix/catphotoapp-typos' checked out at 'C:/Users/14844/Documents/WebDev/repos/freeCodeCamp'

Should I have deleted my local branch before deleting it on the freeCodeCamp repo? If so, then that is the process I’ll do in the future but how do I delete the branch on my end? Should I pull down the current version/state of the repo using:

git fetch origin main

Or should I just use git fetch upstream?

When I first cloned the repo I used two other git commands after the first command above:

git reset --hard upstream/main
git push origin main --force

I believe the second command that uses --force resets my forked copy with the source repo.

It is on my to-do list for today to look into those two commands, but I could use some help now to “clean” up my local clone copy because I have some edits to push on a new branch that I wanted to create. I don’t want to do that until I have this problem fixed. Does anyone know what I should do or would you provide a link explaining what to do for that error?

What branch are you on when deleting?

It should work if you switch/checkout to the main branch before deleting the “fix” branch.

Oops - I was on that branch - I have to run but I’ll switch to main and run it again when I get back and I’m sure it will work - thanks!

1 Like

Also, don’t be surprised if it tells you that you have to use a “-D” instead of “-d” to delete it. You can safely do that since the branch has been merged.

Correct. I just got his message:

error: The branch 'fix/catphotoapp-typos' is not fully merged.
If you are sure you want to delete it, run 'git branch -D fix/catphotoapp-typos'.

I have no problem using -D but what does “not fully merged” mean? Does that mean not merged with the forked copy in my account? If so, I assume that is going to be a problem. How do I get the FCC repo synced with my copy? Should I use:

git push origin my_https_url

Do I do a git merge branch_name before that and then push to my http_url and then delete it?

I just noticed this, but if this is for the fCC repo you wouldn’t normally merge your own fix branch into main. You would push the “fix” branch (and open a PR) and wait until it gets merged into the main repo and then just fetch from the upstream to get your local main branch in sync.

No, it’s already been done - my changes have been merged with FCC main and I deleted my branch from there somehow. here was a Delete branch button. What I’m asking is what’s going on with that error? Do I need to merge MY local changes into MY GitHub account main branch copy of FCC’s repo?

I need to figure this out because I used git log fix/catphotoapp-typos --not main and the log showed that I made a change that I missed and made a change that I forgot to make in the initial push. I can’t remember if I did a second push.

I’ll have to keep a log on my next PR but I think I just want everything synced. I don’t know if this is reckless but I’m going to try:

git fetch upstream
git reset --hard upstream/main
git push origin main --force

My notes are that

  • The 1st command updates my local copy of the freeCodeCamp upstream repository
  • The 2nd command resets my main branch with the freeCodeCamp main
  • The last command pushes my main branch to my origin to have a clean history on your fork on GitHub

Then I can do git diff upstream/main to validate my current main matches the upstream/main. Anyone see a problem with that? Ugh! I need the definitive git manual for beginners.

I always use capital -D when deleting a branch. I’m not sure if the warning is just because you haven’t (won’t) merged your branch into main and haven’t yet fetched the updated remote.

Sorry for the late reply - had to run out and walk a dog. I looked at that stackoverflow post. This article is good as well: GIT: Branch is Not Fully Merged - Brian Childress

I did the nuclear options listed above with --hard and --force. It deleted it but I see it listed when I do git branch -a.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.