There are situations when you need to escape from the regular Git workflow (committing all local changes, pulling all external changes). I’ll describe two such cases.

Don’t commit locally modified files

If, for some reason, you need to change file locally and don’t want to commit the file changes there is a git option –skip-worktree which you can use.

E.g. you may want to update .htaccess file to pull website files from the production server (if they’re missing locally), but you don’t want to commit that change to git since it might cause issues on other environments. You’d just add cd into the root of your project (where your .htaccess file is located) and run something like this:

Copy to Clipboard

Once you’re ready to let Git track your local changes for that file again – you can restore Git management by using the following command:

Copy to Clipboard

Don’t update local files when externally modified

When you want to keep a file as is and not pull the external changes (case with switching to other branches) you can use –assume-unchanged option.

E.g. the other developer is constantly updating his npm/gulp settings and you don’t want to repeat that process locally. You could run something like this:

Copy to Clipboard

Once you’re ready to let those gulp changes flow into your local environment you can restore management to the git by using:

Copy to Clipboard