Skip to content

escape branch name with leading # in example of no upstream set #311

Closed
@robstoll

Description

@robstoll

say you have a branch named #42-my-lovely-branch and would like to push it but forgot to set the upstream branch. You get the following error message:

fatal: The current branch #42-my-lovely-branch has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin #42-my-lovely-branch

This cannot be copy & paste as #42-my-lovely-branch should be escaped with a backslash as follows:

    git push --set-upstream origin \#42-my-lovely-branch

As webtech mentioned here: gitgitgadget/gitgitgadget#112

Using # in the branch name is valid but will cause unexpected problems. If you are using windows cmd shell, # does not need to be escaped. On other shells, it needs to be escaped or quoted. Not sure git should need to figure out where it is running and determine if it needs to escape any characters in the branch name. If the # had not been the first character in the branch name the cut and paste may have worked with unexpected results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions