What's the best practice to “git clone” into an existing folder?

后端 未结 15 1677
情书的邮戳
情书的邮戳 2020-11-28 17:19

I have a working copy of the project, without any source control meta data. Now, I\'d like to do the equivalent of git-clone into this folder, and keep my local changes.

15条回答
  •  春和景丽
    2020-11-28 17:53

    Don't clone, fetch instead. In the repo:

    git init
    git remote add origin $url_of_clone_source
    git fetch origin
    git checkout -b master --track origin/master # origin/master is clone's default
    

    Then you can reset the tree to get the commit you want:

    git reset origin/master # or whatever commit you think is proper...
    

    and you are like you cloned.

    The interesting question here (and the one without answer): How to find out which commit your naked tree was based on, hence to which position to reset to.

提交回复
热议问题