git fetch --depth 10
this will fetch all newer commits from origin and then cut off the local history to depth of 10.
for normal purposes your local git history is now at length of 10. but beware that the files of the old commits still occupy space on your disk and that the commits still exist in the remote repository.
if your aim was to have a shorter log because you currently don't need years worth of commit history then you are done. your log will be short and most common git commands now only see 10 commits.
if your aim was to free disk space because older commits have huge binary blobs which you don't need to work now then you have to actually remove the files from your disk. see below for a short description how to do so.
if your aim was to completely remove the old commits (for example to remove a password from old commits) then this is not the correct command to do so. the commits are still visible and accesible for all who have access to the remote repository. you need to remove the commits from the remote repository. see below for links with more info on how to remove commits from a remote repo.
to undo a --depth
and get the entire history again:
git fetch --unshallow
how to free disk space
data loss warning! read the notes and pay attention to what you are doing.
after a git fetch --depth xx
the files of the old commits still hang around on disk. git won't remove those files as long as some references are still holding on to those commits. so you need to remove those references. those references are, roughly in order of data pertinence: the reflog, stashes, tags, and branches.
the reflog is typically safe to clear. read the notes below for when you might want to think twice before clearing the reflog.
to clear the reflog:
git reflog expire --expire=all --all
stashes should be temporary anyways. so just drop them like it's hot:
git stash drop
tags and branches typically hold data you want to keep. so be carefull with the next two commands. read the notes below for more information.
to remove all tags:
git tag -l | xargs git tag -d
to remove a branch:
git branch -d branchname
beware of data loss! read the notes below and think before you delete.
once you have removed all references you can call the git garbage collector to actually remove the files of the old commits:
git gc --prune=now
now the files should be removed from disk.
notes
tags and branches are often synced with the remote repo. but they can also exists in your local repo only. those that exists on the remote repo can always be fetched again if needed. those that exists only locally will be lost if you delete them.
the easiest way to backup your local tags and branches is to copy your entire local repo to another disk. you can also clone your repo locally. but make sure to include all tags and branches as a simple clone will not. see below for a link explaining how to do so.
the reflog is something like a local history of past local repository states. it is entirely local to your local repository. many git commands will record the previous state of the local repository in the reflog. with the reflog you can undo some commands or at least retrieve lost data if you made a mistake. so think before you clear the reflog.
old reflog entries are cleared automatically after a certain time by git garbage collector (about 90 days IIRC). tags and branches however will stay around forever. so if you want to free disk space you have to at least remove the tags and branches manually.
see also
https://linuxhint.com/git-shallow-clone-and-clone-depth/
http://gitready.com/intermediate/2009/02/09/reflog-your-safety-net.html
How do I edit past git commits to remove my password from the commit logs?
Delete all local git branches
Fully backup a git repo?