Given $PWD is /home/a-user/ghq/github.com/gh-user/project/src, butt ghq will change your $PWD to /home/a-user/ghq/. Press cd - to get back where you were before.
Note: If your usecase demands this script, I would suggest to use z like dir jumpers instead.
This could be a simpler solution https://news.ycombinator.com/item?id=27994905