How do I clone into a non-empty directory?

前端 未结 16 1298
庸人自扰
庸人自扰 2020-11-22 06:20

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 bu

相关标签:
16条回答
  • 2020-11-22 06:24

    This worked for me:

    git init
    git remote add origin PATH/TO/REPO
    git fetch
    git reset origin/master  # Required when the versioned files existed in path before "git init" of this repo.
    git checkout -t origin/master
    

    NOTE: -t will set the upstream branch for you, if that is what you want, and it usually is.

    0 讨论(0)
  • 2020-11-22 06:27

    A slight modification to one of the answers that worked for me:

    git init
    git remote add origin PATH/TO/REPO
    git pull origin master
    

    to start working on the master branch straight away.

    0 讨论(0)
  • 2020-11-22 06:29

    I got the same issues when trying to clone to c/code

    But this folder contains a whole bunch of projects.

    I created a new folder in c/code/newproject and mapped my clone to this folder.

    git for desktop then asked of my user and then cloned fine.

    0 讨论(0)
  • Here's what I ended up doing when I had the same problem (at least I think it's the same problem). I went into directory A and ran git init.

    Since I didn't want the files in directory A to be followed by git, I edited .gitignore and added the existing files to it. After this I ran git remote add origin '<url>' && git pull origin master et voíla, B is "cloned" into A without a single hiccup.

    0 讨论(0)
  • 2020-11-22 06:34

    I have used this a few moments ago, requires the least potentially destructive commands:

    cd existing-dir
    git clone --bare repo-to-clone .git
    git config --unset core.bare
    git remote rm origin
    git remote add origin repo-to-clone
    git reset
    

    And voilá!

    0 讨论(0)
  • 2020-11-22 06:34

    this is work for me ,but you should merge remote repository files to the local files:

    git init
    git remote add origin url-to-git
    git branch --set-upstream-to=origin/master master
    git fetch
    git status
    
    0 讨论(0)
提交回复
热议问题