--- aliases: - /2020/06/git categories: - git date: '2020-06-01' layout: post slug: git title: My own git cheatsheet --- I noticed I always google the same procedures... ## Remove a file from a commit Direct remove without editing anything: ``` git reset HEAD^ -- path/to/file git commit --amend --no-edit ``` Step-by-step: ``` git reset --soft HEAD~1 git reset HEAD path/to/unwanted_file git commit -c ORIG_HEAD ``` [Source](https://stackoverflow.com/questions/12481639/remove-files-from-git-commit) ## Only checkout a subset of files stored in `git` LFS GIT_LFS_SKIP_SMUDGE=1 gh repo clone orgname/reponame Then checkout only specific files: git lfs fetch --include="pattern*" --exclude="" git lfs checkout ## Configure git to automatically run git submodule update This works when switching branches: git config --global submodule.recurse true