0

I have noticed that Git clone can easily download all files of a GitHub repository to to a directory named exactly as the GitHub repository (without having to deal with archives).

If a directory with the same of the repository already exists, Git will throw an error:

fatal: destination path 'REPOSITORY_NAME' already exists and is not an empty directory.

In such case, perhaps a good coping with it is to somehow clone anyway but to just save the data in a directory with a different name.

3
  • then you could always do something like mkdir foo; cd foo; git clone whatever...; mv cloned-directory ../my-name-for-the-repo; cd ..; rmdir foo. Not that I'd admit to having done that but anyway... (I have done that at least when unpacking tarballs, since renaming any created directory on extraction is more awkward there.)
    – ilkkachu
    Commented Sep 18, 2021 at 13:30
  • What name should be used if the default name isn't available? Doesn't the existence of the directory indicate an issue?
    – Kusalananda
    Commented Sep 18, 2021 at 13:58
  • @Kusalananda I assume that if I want to keep the existing directory as-is I would move it to some storage directory far away. I think that the existence of a directory with the same name might be mere legacy, not necessarily a problem. Commented Sep 18, 2021 at 14:18

1 Answer 1

3

git clone takes a directory name on the command line too. From man git-clone:

NAME
       git-clone - Clone a repository into a new directory

SYNOPSIS
       git clone [--template=<template_directory>]
                 [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
                 [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
                 [--dissociate] [--separate-git-dir <git dir>]
                 [--depth <depth>] [--[no-]single-branch] [--no-tags]
                 [--recurse-submodules[=<pathspec>]] [--[no-]shallow-submodules]
                 [--[no-]remote-submodules] [--jobs <n>] [--sparse]
                 [--filter=<filter>] [--] <repository>
                 [<directory>]

E.g.

$ git clone https://git.savannah.gnu.org/git/bash.git blahblah
Cloning into 'blahblah'...
1
  • Oh, I read the question as if they wanted to use the default directory name if possible, but some other name if that wasn't possible, automatically...
    – Kusalananda
    Commented Sep 18, 2021 at 14:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .