Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save suchipi/287625610a6fc69854ba72b54558cdc2 to your computer and use it in GitHub Desktop.
Save suchipi/287625610a6fc69854ba72b54558cdc2 to your computer and use it in GitHub Desktop.
bash "go to repo root" snippet
#!/usr/bin/env bash
# This isn't 100% foolproof, but it's probably good enough for random scripts in your git repo
THIS_FILE="$BASH_SOURCE"
THIS_DIR=$(dirname "$THIS_FILE")
ROOT_DIR=$(realpath "$THIS_DIR/..")
cd "$ROOT_DIR"
# and then you can do stuff with guarantees about $PWD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment