Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 673145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:33:48+00:00 2026-05-14T00:33:48+00:00

I have directory A with files matching directory B. Directory A may have other

  • 0

I have directory A with files matching directory B. Directory A may have other needed files. Directory B is a git repo.

I want to clone directory B to directory A but git-clone won’t allow me to since the directory is non-empty.

I was hoping it would just clone .git and since all the files match I could go from there?

I can’t clone into an empty directory because I have files in directory A that are not in directory B and I want to keep them.

Copying .git is not an option since I want refs to push/pull with and I don’t want to set them up manually.

Is there any way to do this?

Update: I think this works, can anyone see any problems? –>

cd a
git clone --no-hardlinks --no-checkout ../b a.tmp 
mv a.tmp/.git .
rm -rf a.tmp
git unstage # apparently git thinks all the files are deleted if you don't do this
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:33:48+00:00Added an answer on May 14, 2026 at 12:33 am

    In the following shell commands existing-dir is a directory whose contents match the tracked files in the repo-to-clone git repository.

    # Clone just the repository's .git folder (excluding files as they are already in
    # `existing-dir`) into an empty temporary directory
    git clone --no-checkout repo-to-clone existing-dir/existing-dir.tmp # might want --no-hardlinks for cloning local repo
    
    # Move the .git folder to the directory with the files.
    # This makes `existing-dir` a git repo.
    mv existing-dir/existing-dir.tmp/.git existing-dir/
    
    # Delete the temporary directory
    rmdir existing-dir/existing-dir.tmp
    cd existing-dir
    
    # git thinks all files are deleted, this reverts the state of the repo to HEAD.
    # WARNING: any local changes to the files will be lost.
    git reset --hard HEAD
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a directory with files that look like this: 001_something.php 002_something_else.php 004_xyz.php 005_do_good_to_others.php
I have a directory of XML files... for example: result.xml result2.xml result3.xml resultNth.xml (because
I have a directory of ZIP files (created on a Windows machine). I can
I have directory with > 1000 .html files, and would like to check all
I have a directory of many files in Windows Vista. I'd like in a
I have a directory containing several files, some of which have spaces in their
I have a directory with around 15-30 thousand files. I need to just pull
I have a directory with a lot of files in it named: file001.pdf, file002.pdf
I have a directory and in it has several files. I'm trying to decrypt
I have a directory full (~10 3 , 10 4 ) of XML files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.