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:

  1. Any new files/folders you created will be removed, including sub-repositories.
  2. Any files you’ve changed that already existed in the repo will NOT have their changes stashed/saved.
  3. 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.

  4. 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?

Linkage that helped me: one two

Mario Loria is a builder of diverse infrastructure with modern workloads on both bare-metal and cloud platforms. He's traversed roles in system administration, network engineering, and DevOps. You can learn more about him here.