Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'git init -b <branch name>' command in terminal is throwing an 'unknown switch' error

I am trying to add an existing project to GitHub using the command line. I am in the relevant working directory in the terminal and am trying to use the git init -b main command.

Initially, I was getting an error relating to xcode:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun 

I tried xcode-select --install but the software was unavailable from the update server, so I downloaded 'Command Line Tools for Xcode 12' from https://developer.apple.com/download/more/.

Now on entering git init -b main I am getting the following:

error: unknown switch `b' usage: git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]] [<directory>]  --template <template-directory>                       directory from which templates will be used --bare                create a bare repository --shared[=<permissions>]                       specify that the git repository is to be shared amongst several users -q, --quiet           be quiet --separate-git-dir <gitdir>                       separate git dir from working tree 

I am running git version: 2.24.3 (Apple Git-128)

Any help much appreciated!

like image 726
pjgearing Avatar asked Nov 11 '20 13:11

pjgearing


People also ask

How do I initialize a git branch?

The easiest way to create a Git branch is to use the “git checkout” command with the “-b” option for a new branch. Next, you just have to specify the name for the branch you want to create. To achieve that, you will run the “git checkout” command with the “-b” option and add “feature” as the branch name.

How do I resolve a fatal error in git?

A Git command needs to be run on a specific repository, so this error typically occurs when a Git command is run in a directory that Git doesn't know about. In these cases, the fix is to make sure that you are both working in the correct folder and that you set up your repository right.

What is the command to initialize git on the?

The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository. Most other Git commands are not available outside of an initialized repository, so this is usually the first command you'll run in a new project.


1 Answers

git 2.24 doesn't have option -b/--initial-branch. It was added in git 2.28. You need to upgrade to use the option.

Or, as @matt said, create a repo and then rename the branch:

git init repo cd repo git branch -m master slave 
like image 125
phd Avatar answered Oct 06 '22 14:10

phd