Error Initialize GIT git init --initial-branch=main

From KoanSoftware Wiki
Jump to: navigation, search

Error Initialize GIT git init --initial-branch=main

When initializing a new repository with old syntax you may face to this error

> git init --initial-branch=main
error: unknown option `initial-branch=main'

Example of Gitlab suggested regular code

cd existing_folder
git init --initial-branch=main
git remote add origin git@gitlab.com:path/to/project.git
git add .
git commit -m "Initial commit"
git push -u origin main


Fix the problem using this way

cd existing_folder
git init
git checkout -b  main
git remote add origin git@gitlab.com:path/to/project.git
git add .
git commit -m "Initial commit"
git push -u origin main