ppoliani
ppoliani

Reputation: 4906

Weird git branch name

I was trying to run the following command:

git branch --set-upstream-to=staging

And the result was not what i was expected. Instead of setting the upstream branch it created a new branch called --set-upstream-to=staging and the problem is that i cannot remove it.

Is there any way to make the

git branch -d --set-upstream-to=staging

command run successfully?

The error I get when I try to run the above command is: error: unknown switch `s'

enter image description here

I can confirm the existence of the branch when i run git branch

Upvotes: 2

Views: 834

Answers (3)

Boldewyn
Boldewyn

Reputation: 82724

The answer of blue112 should work perfectly fine. However, if you find, that nothing else works, you can go plumbing. Look at the .git/refs/heads folder. It should look something like this:

$ ls .git/refs/heads
master
other-branch
--set-upstream-to=staging

Delete the file .git/refs/heads/--set-upstream-to=staging. Then the branch is gone. If you had commits there, they are now dangling, so you need to recover them manually. If not, you are done now.

Upvotes: 1

Kevin Yan
Kevin Yan

Reputation: 1236

If you have an initialized branch in your local system and wanna push it to the remote git repository you can:

cd git_working_directory git branch --set-upstream your_branch origin/your_branch git push

after that commands are executed your local branch will be pushed into remote repository and make a new branch

Upvotes: -1

blue112
blue112

Reputation: 56412

Usually, when you have weird filename / branchname / anythingname, you can make the command line not try to parse using:

 git branch -d -- --set-upstream-to=staging

The "--" is here to inform getopt (the module that is parsing the options) to stop parsing options and start parsing arguments.


By the way, there's no way git let me create a branch starting with a dash. I'm not sure how you did that.

Upvotes: 2

Related Questions