Skip to main content

How to Clone a Local Git Repository into Another Folder

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

git clone doesn't need GitHub: it can copy a repository from another folder on your own computer. That gives you a fresh copy with only what's committed, which is the quickest way to check that a project works from scratch, the way someone else would get it. This guide clones a local repository with Git 2.56.1.

Syntax​

Syntax
git clone <path to repository> <new folder>
PartWhat it means
<path to repository>The folder of the repository to copy, such as notes or ../notes
<new folder>The name of the copy. It must not exist yet, or must be empty

Git's clone documentation says it "Clones a repository into a newly created directory", and for the folder: "Cloning into an existing directory is only allowed if the directory is empty."

The Example​

A small repository called notes holds one commit with a README.md. The guide clones it into a new folder, notes-copy, next to it.

Prerequisites​

  • Git. Run git --version to see which one you have; this guide uses Git 2.56.1.

Step 1: Clone the Repository​

From the folder that holds notes:

Terminal
git clone notes notes-copy
Output
Cloning into 'notes-copy'...
done.

The terminal after git clone notes notes-copy: Cloning into 'notes-copy'... then done.

Git created notes-copy and copied the committed files and the whole history into it. Anything you never committed in notes stays behind. The command works unchanged in PowerShell.

Step 2: Look Inside the Copy​

Go into the copy and check its history, its source and its state:

Terminal
cd notes-copy
git log --oneline
git remote -v
git status
Output
09c582a (HEAD -> main, origin/main, origin/HEAD) Add the notes
origin /Users/you/source/notes (fetch)
origin /Users/you/source/notes (push)
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

The terminal in notes-copy: git log shows the commit Add the notes, git remote -v shows origin pointing at the notes folder for fetch and push, and git status says the branch is up to date and the tree is clean.

  • git log shows the same commit as the original.
  • git remote -v shows that the copy's origin is the original folder, so git pull there would fetch new commits from notes.
  • git status shows a clean copy of the last commit.

Common Mistakes​

MistakeWhat happensDo this instead
Cloning into a folder that already exists and has filesfatal: destination path 'notes-copy' already exists and is not an empty directory.Pick a new name, or delete the old copy first
Leaving out the new name, next to the original: git clone notesfatal: destination path 'notes' already exists and is not an empty directory., because Git names the copy after the sourceAlways give a new name when cloning on the same computer

Troubleshooting​

SymptomLikely causeFix
destination path ... already exists and is not an empty directoryA folder with that name is already thereChoose another name
A file you expected is missing from the copyIt was never committed in the originalCommit it there, then clone again

FAQ​

Do I need --local?​

No. The documentation says that when "the repository is specified as a local path (e.g., /path/to/repo), this is the default, and --local is essentially a no-op."

How do I get rid of the copy?​

Delete its folder. The original isn't affected.

Conclusion​

git clone notes notes-copy made an independent copy of the committed project, with origin pointing back at the original. Give the copy a new name, and remember that uncommitted files don't come along.

Additional Resources​