gives me
\ngit.exc.GitCommandError: Cmd('git') failed due to: exit code(129)\n cmdline: git init --initial-branch=main\n stderr: 'error: unknown option `initial-branch=main'\nusage: git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]] [<directory>]\n
I have to resort to this
\ninit_git(path_to_folder_with_no_working_tree)\n\ndef execute(*args, supress_exception=False, cwd=None):\n cur_dir = os.getcwd()\n\n try:\n if cwd:\n os.chdir(cwd)\n\n proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n\n out, err = proc.communicate()\n out = out.decode(\"utf-8\")\n err = err.decode(\"utf-8\")\n if err and not supress_exception:\n raise Exception(err)\n else:\n return out\n finally:\n os.chdir(cur_dir)\n\n\ndef init_git(project_directory):\n # workaround for issue #1\n if not os.path.exists(os.path.join(project_directory, \".git\")):\n execute(\n \"git\",\n \"config\",\n \"--global\",\n \"init.defaultBranch\",\n \"main\",\n cwd=project_directory,\n )\n execute(\"git\", \"init\", cwd=project_directory)\n
Is there a better way to do the same thing?
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"GitPython does nothing more but to execute git like so: git init --initial-branch=main
, which might not work with all git versions. My suspicion is that the flag is a more recent feature than the config option, which is why that one works. On 2.30.1 it's definitely available, and it seems to have been added about a year ago.
-
gives me
WorkaroundI have to resort to this
Is there a better way to do the same thing? |
Beta Was this translation helpful? Give feedback.
-
GitPython does nothing more but to execute git like so: |
Beta Was this translation helpful? Give feedback.
GitPython does nothing more but to execute git like so:
git init --initial-branch=main
, which might not work with all git versions. My suspicion is that the flag is a more recent feature than the config option, which is why that one works. On 2.30.1 it's definitely available, and it seems to have been added about a year ago.