简体   繁体   中英

How to 'sync' github with a local directory (recovered system restore) that is not under git

I have a project on a local machine that has all the sensitive excluded files from the associated github repository. However, the local directory is not under git control to compare and update.

I am somehow looking to git clone all files that are in the repository while keeping the files that already exist locally (ie in my .gitignore ) and get back in sync with my github repository without having to do a fresh clone.

You could always "initialize" the directory as a git repo, add the remote repository to sync with, then checkout whatever branch you're interested in. If all sensitive files are indeed ignored, they should remain untouched while the rest of the files are updated to the designated remote HEAD.

cd /path/to/local/copy
git init
git remote add origin <remote-url>
git fetch
git checkout -b <local-branch-name> origin/<remote-branch-name>

If, for some reason, you don't want to keep tracking the local directory as a git repository, just delete the .git folder after you're done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM