How do I clone into a non-empty directory?

前端 未结 16 1504
庸人自扰
庸人自扰 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:48

    I had a similar problem with a new Apache web directory (account created with WHM) that I planned to use as a staging web server. I needed to initially clone my new project with the code base there and periodically deploy changes by pulling from repository.

    The problem was that the account already contained web server files like:

    .bash_history
    .bash_logout
    .bash_profile
    .bashrc
    .contactemail
    .cpanel/
    ...
    

    ...that I did not want to either delete or commit to my repository. I needed them to just stay there unstaged and untracked.

    What I did:

    I went to my web folder (existing_folder):

    cd /home/existing_folder
    

    and then:

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

    It displayed (as expected) a list of many not staged files - those that already existed initially from my cPanel web account.

    Then, thanks to this article, I just added the list of those files to:

    **.git/info/exclude**
    

    This file, almost like the .gitignore file, allows you to ignore files from being staged. After this I had nothing to commit in the .git/ directory - it works like a personal .gitignore that no one else can see.

    Now checking git status returns:

    On branch master
    nothing to commit, working tree clean
    

    Now I can deploy changes to this web server by simply pulling from my git repository. Hope this helps some web developers to easily create a staging server.

提交回复
热议问题