
Some commands used in this article were git log, git reflog, and git checkout.These commands are very useful when interacting with a remote repository. Other commands are needed to understand the effects of git prune.
GIT FETCH AND GIT PULL SOFTWARE
It is highly unlikely you will ever need to invoke git prune in a day to day software engineering capacity. The git prune command is intended to be invoked as a child command to git gc.

This safely leaves local work in local/origin. git remote prune origin will only prune the refs in remote/origin. A repository will have local/origin and remote/origin ref collections. No git remote prune origin will only delete the refs to remote branches that no longer exist. Does Git Remote Prune Origin Delete the Local Branch?

It will then delete remote refs that are no longer in use on the remote repository. It will connect to a shared remote repository remote and fetch all remote branch refs. Git fetch -prune is the best utility for cleaning outdated branches. As discussed in the overview section, git prune will delete locally detached commits. The generic git prune command is entirely different. To conclude our git prune simulation demo we must clear the reflog

Again, these are all implementation details that git gc handles and git prune should not be used standalone. In addition to preserving history in the reflog, Git has internal expiration dates on when it will prune detached commits. For more info on git reflog visit the git reflog page. You should see some output describing the sequence of actions we took to get here. We can investigate by running git reflog. Most likely Git is storing a reference to our detached commit in the reflog. This is also a good example of how it is hard to fully lose data with Git. This is a prime example of why git prune is not to be used stand-alone outside of git gc. Somewhere Git is still maintaining a reference to it. Why would this happen? Well, the commit is most likely not fully detached. Empty output implies that the prune will not actually delete anything. This command will most likely return empty output. ~/git-prune-demo $ git prune -dry-run -verbose First though, let us return to the main branch using git checkout If we examine the log here we can see that the "added another line to hello.txt" commit is now back in the log output! Now that we know the repository is in a good simulation state with a detached commit we can practice using git prune. When we check out the detached commit, Git is thoughtful enough to give us a detailed message explaining that we are in a detached state. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.
