Useful git commands
May 8, 2022

Stop tracking a file

git rm --cached <file>git update-index --assume-unchanged <file>git update-index --skip-worktree <file>

Remove a large file from commit history

cd to your local working folder and run the following command:

git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch FOLDERNAME" -- --all

replace FOLDERNAME with the file or folder you wish to remove from the given git repository.

Once this is done run the following commands to clean up the local repository:

rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

Now push all the changes to the remote repository:

git push --all --force

Delete some commits from the history

  • Open interactive rebase
git rebase -i HEAD~#
  • delete the line of the commits from the file
  • Merge
  • commit