Skip to content

Instantly share code, notes, and snippets.

@ayaz-ac
Created March 30, 2022 16:50
Show Gist options
  • Save ayaz-ac/177f083f16ae83e82c9c61ccfabbbca3 to your computer and use it in GitHub Desktop.
Save ayaz-ac/177f083f16ae83e82c9c61ccfabbbca3 to your computer and use it in GitHub Desktop.
Bash function to checkout and update dependencies in a Rails project
cob() {
git checkout $1
git fetch origin
update_js="$(git diff --name-only origin/$1 package.json)"
update_sql="$(git diff --name-only origin/$1 db/structure.sql)"
update_gem="$(git diff --name-only origin/$1 Gemfile)"
git pull
if [ -n "${update_js}" ]; then
yarn install --check-files
fi
if [ -n "${update_sql}" ]; then
rails db:reset
fi
if [ -n "${update_gem}" ]; then
bundle
fi
}
@ayaz-ac
Copy link
Author

ayaz-ac commented Mar 30, 2022

Example of utilisation: cob main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment