Home > front end >  git branch list have "--delete", "-d", "-delete" after run git branch
git branch list have "--delete", "-d", "-delete" after run git branch

Time:09-13

I'm new to git, and first I cloned a remote repository doing like this:

git clone https://git_romote_url/repository_name.git

and then I created a branch locally by:

 git checkout -b branch_name

then I wanted to delete the branch branch_name, so I tried the following command:

 git branch –delete branch_name
 git branch –d branch_name
 git branch –-delete branch_name

I knew the first command is wrong (missing a horizontal line), so I tried the following two.

But after this, when I shown branches by:

git branch

The branches list showed:

* master
  –-delete
  –d
  –delete

And when I want to delete either one of "--delete", "-d" or "-delete" by:

git branch --delete --delete
git branch --delete -d
git branch --delete -delete

I got:

fatal: branch name required

I have searched the internet, but found nothing like my problems.

So, could someone please help explain why this happens and how should I handle this problem (I want to delete the three branches except master if it is ok and necessory to do this) .

Any help or hint is very appricated, and thanks in advance.

CodePudding user response:

Look this character: a

Now look at this character: â

They look exactly the same, don't they? Well, no, they don't. One's an ordinary lowercase A, and one is a lowercase A with a hat on it. So they look different. But they're both the letter "a", right? (This is a rhetorical question: you're supposed to think about it, and decide whether it's right, wrong, or maybe both or neither, and under what conditions.)

Now, look at this character: -

Then look at this one: –

They are the same, aren't they? Or are they? Let me line up a bunch of them:

    -----
    –––––

There are five dashes on each line. Can you see that they are different? Here they are again but in fixed-width computer font:

-----
–––––

Do they look the same, or do they look different? (On my screen, the en-dash characters in the fixed-width font merge to make a solid line, while the hyphens don't so that there are five separate hyphens instead of one solid line. In the variable-pitch font, the en-dashes are a bit longer than the hyphens, but shorter than em-dashes: they don't merge, but they come close.)

Now, luckily for us, you cut-and-pasted your branch names, so we can actually tell what Unicode characters these are. Your branch named –-delete is not --delete (two dashes), it's en-dash, dash, d, e, l, e, t, e. To type this en-dash character on my Mac keyboard, I use the option key, , plus the - key. (Using SHIFT- gets an em-dash.)

Your –d and –delete branch names are very similar: both start with an en-dash. Find out how to type in an en-dash, and use that to run git branch -d to delete them. For more about en-dash and em-dash, see https://proofed.com/writing-tips/how-to-type-an-en-dash-and-em-dash-on-windows-and-mac-devices/ for instance.

  • Related