257

I am trying to clone repo from another directory.

Lets say I have one repo in C:/folder1 and C:/folder2

I want to clone the work in folder1 into folder2.

What would I type into the command prompt to do this?

It seems that often when cloning a URL is provided rather then a file path, however, at this moment I am just practicing and trying to get use to Git.

3
  • 10
    you can use git clone C:\folder1\.git folder2. You need to run it from the directory where you want folder2 to appear
    – Akash
    Commented Jan 10, 2014 at 13:05
  • 1
    If you're in windows and it's still not working, you may need to prepend `file:\` to repository path. See this stackoverflow.com/questions/37422428/…
    – Jacob H
    Commented Jan 3, 2018 at 21:55
  • 1
    Gosh this QA is really hard to find!
    – Qwerty
    Commented Mar 22, 2022 at 15:16

8 Answers 8

269
cd /d c:\
git clone C:\folder1 folder2

From the documentation for git clone:

For local repositories, also supported by git natively, the following syntaxes may be used:

/path/to/repo.git/

file:///path/to/repo.git/

These two syntaxes are mostly equivalent, except the former implies --local option.

3
  • 6
    @grahamesd, really you do not need to map a network folder as a drive because of GIT can clone its quite good in such way: git clone //pc_name/git Commented Jan 10, 2017 at 9:26
  • Do you need to remember the full path of the destination and then type it out? Or is there some other way to either navigate there, or autocomplete? Long paths can be difficult to remember. Commented Dec 19, 2022 at 14:27
  • 1
    @RasmusLarsen, I guess you mean the source, not the destination? Relative paths should work, e.g. git clone ../some/path. And / or, you can manage your remotes. Cloning like this should automatically configure an origin remote for future use, e.g. fetching or pushing commits.
    – Chris
    Commented Dec 19, 2022 at 14:47
43

It is worth mentioning that the command works similarly on Linux:

git clone path/to/source/folder path/to/destination/folder
1
  • 2
    or go to the directory where you want to clone the main project to, and git clone path/to/source/folder
    – Sahin
    Commented Jun 17, 2022 at 9:05
27

None of these worked for me. I am using git-bash on windows. Found out the problem was with my file path formatting.

WRONG:

git clone F:\DEV\MY_REPO\.git

CORRECT:

git clone /F/DEV/MY_REPO/.git

These commands are done from the folder you want the repo folder to appear in.

2
  • The following command is working in bash: git clone F:\DEV\MY_REPO
    – M.Hassan
    Commented Feb 26, 2017 at 18:21
  • 2
    For git-bash you can use either backslash / or double slash `\\`. But no single slash.
    – Elad Weiss
    Commented Mar 4, 2020 at 14:27
10

It's as easy as it looks.

14:27:05 ~$ mkdir gittests
14:27:11 ~$ cd gittests/
14:27:13 ~/gittests$ mkdir localrepo
14:27:20 ~/gittests$ cd localrepo/
14:27:21 ~/gittests/localrepo$ git init
Initialized empty Git repository in /home/andwed/gittests/localrepo/.git/
14:27:22 ~/gittests/localrepo (master #)$ cd ..
14:27:35 ~/gittests$ git clone localrepo copyoflocalrepo
Cloning into 'copyoflocalrepo'...
warning: You appear to have cloned an empty repository.
done.
14:27:42 ~/gittests$ cd copyoflocalrepo/
14:27:46 ~/gittests/copyoflocalrepo (master #)$ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)
14:27:46 ~/gittests/copyoflocalrepo (master #)$ 
9

In case you have space in your path, wrap it in double quotes:

$ git clone "//serverName/New Folder/Target" f1/
9

Using the path itself didn't work for me.

Here's what finally worked for me on MacOS:

cd ~/projects
git clone file:///Users/me/projects/myawesomerepo myawesomerepocopy

This also worked:

git clone file://localhost/Users/me/projects/myawesomerepo myawesomerepocopy

The path itself worked if I did this:

git clone --local myawesomerepo myawesomerepocopy
1
  • Yes, the OP's example is Windows, but the question isn't tagged Windows, so I posted in the hopes of helping Mac users Commented Jan 3, 2020 at 19:00
5

Use git clone c:/folder1 c:/folder2

git clone [--template=<template_directory>] [-l] [-s] [--no-hardlinks]
[-q] [-n] [--bare] [--mirror] [-o <name>] [-b <name>] [-u <upload-pack>]
[--reference <repository>] [--separate-git-dir <git dir>] [--depth <depth>]
[--[no-]single-branch] [--recursive|--recurse-submodules] [--]<repository>
[<directory>]


<repository>

    The (possibly remote) repository to clone from.
    See the URLS section below for more information on specifying repositories.
<directory>

    The name of a new directory to clone into.
    The "humanish" part of the source repository is used if no directory 
    is explicitly given (repo for /path/to/repo.git and foo for host.xz:foo/.git).
    Cloning into an existing directory is only allowed if the directory is empty.
5

I am using git-bash in windows.

The simplest solution is to just replace \ in the source folder path with forward slashes(/):

Example: c:\dev\source will become c:/dev/source

  1. Start the git-bash on the destination folder.

  2. Run the git clone using the forward slashed source folder path:

    git clone c:/dev/source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.