When to use Push-Location versus Set-Location?

jaccus picture jaccus · Sep 23, 2015 · Viewed 8.1k times · Source

At first sight Set-Location and Push-Location PowerShell cmdlets look alike when it comes to changing the current directory.

What are use cases for each? When would one choose to use one over the other?

Answer

arco444 picture arco444 · Sep 23, 2015

They will both change the working directory but using Push-Location will add the current working directory to the top of a stack before changing to the new working directory. You can then use Pop-Location to traverse back down the stack through the previous working directories.

Set-Location will just change the working directory in the same way that cd would.

Set-Location = cd
Push-Location = pushd
Pop-Location = popd