Repository setup instructions - use of git branch -M flag

[posting this here because I can’t see a place to contact Github directly or a repository to add an issue]

I’ve fallen for this twice now. I know I should not blindly copy commands, but I have done twice, possibly because it’s from a source I trust.

When creating a new repository that I have been working on locally, I follow the New Repository UI which brings me to the “Quick setup — if you’ve done this kind of thing before” dialog / instructions page. It’s here I have the issue.

Under the subheading " …or push an existing repository from the command line", I usually switch main formerly (master) for develop, as I use that as my “default” branch until v1. I copy the commands one at a time swapping “main” for “develop”. The instructions are:

git remote add origin<repo>.git
git branch -M main
git push -u origin main

The last couple of times, I’ve been in a feature branch. The second command, with the -M flag, is needlessly aggressive and confusing. So I’m in my feature branch which is suddenly, forcefully renamed to main/develop. My git status prompt changes to “develop” and it seems my feature branch has disappeared. In fact, it’s there but has forcefully overwritten develop. Luckily I don’t think I lost any work with this, but it seems I could easily have.

Why the (effective) --force option? I’m guessing this flag was introduced when “master” became “main” by convention here on Github but not in git itself. This is a very unfortunate and disconcerting side-effect. There must be a better way to achieve this. At the very least, please warn users about possible side-effects of using this flag.

Hello @hughbris and welcome to the community!

Thanks for this feedback! I can understand how this would be confusing and frustrating. The best place to submit feature requests and share more details about your use case is through our official product feedback form so that our product team can track your request.