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!
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With