git fetch origin
git reset --hard origin/master
git clean -dffx
If you run the above commands instead of just a git pull, your repo will be synced exactly (1:1) with its remote. This means:
- Any new files/folders you created will be removed, including sub-repositories.
- Any files you’ve changed that already existed in the repo will NOT have their changes stashed/saved.
Any .gitignore files are not followed! Meaning any ignored files in a particular directory that were added by a program/script will be removed!! >This can be changed by removing the -x from git clean.
BE CAREFUL. Something you might have been working on will get rm’ed.
Oh and as a side note, when doing git add’s, it is wise to do a “git add -A” as this will include any removals as well. So for me, how I have this setup in my zshrc:
function update () { cur=$(pwd); cd ~/env; git fetch origin; git reset --hard origin/master; git clean -dffx; cd $cur; cur=''; source ~/.zshrc }
Pretty nifty huh?