If you're using zsh, make sure you have enabled
setopt auto_pushd (in oh-my-zsh, which I'm fan of, this is the default).
Now you can
popd to go back in browsing history.
You can also use
dirs -v to show all stacked directories.
If you're using bash, you can probably alias