Issue
I want to execute a command like 'git tag -l' inside a directory /home/user/git/app/ but I am actually in /home/user. How can I do that in bash without changing my working directory?
So NOT:
cd /home/user/git/app && git tag -l
because that actually changes my working directory and have to do 'cd /home/user' again.
Solution
Just bracket the whole thing. That will run it in a subshell which can go to any directory and not affect your 'current working' one. Here's an example.
noufal@sanctuary% pwd
/tmp/foo
noufal@sanctuary% (cd ../bar && pwd && ls -a )
/tmp/bar
./ ../
noufal@sanctuary% pwd
/tmp/foo
noufal@sanctuary%
Answered By - Noufal Ibrahim Answer Checked By - Dawn Plyler (WPSolving Volunteer)