Skip to content

Instantly share code, notes, and snippets.

@diodonfrost
diodonfrost / postgresql-create-user-with-permissions.sh
Created June 16, 2025 20:24
Create simple user with permissions on PostgreSQL
-- 1. Create the user role
CREATE USER app_user PASSWORD 'secure_password';
-- 2. Give them access to the database
GRANT CONNECT ON DATABASE ma_base TO app_user;
-- 3. Give them access to the schema
GRANT USAGE ON SCHEMA public TO app_user;
-- 4. Give them privileges on the tables
@diodonfrost
diodonfrost / git-replace.sh
Created September 5, 2023 21:54
Replace a string in whole Git history
# Replace the string "foo" by "bar" in all .yml files in the whole Git history
git filter-branch -f --tree-filter "find . -type f -name '*.yml' -exec sed -i -e 's/foo/bar/g' {} \;"
# Replace the string "foo" by "bar" in all files in the whole Git history
git filter-branch -f --tree-filter "find . -type f -exec sed -i -e 's/foo/bar/g' {} \;"
@diodonfrost
diodonfrost / git-move-folder-with-history.sh
Last active September 5, 2023 21:19
Move folder and keep Git history
# Move/Rename folder "foo/my-old-folder" to "foo/my-new-folder" and keep history
git filter-branch -f --tree-filter 'test -d foo/my-old-folder && mv foo/my-old-folder foo/my-new-folder || echo "Nothing to do"' HEAD
@diodonfrost
diodonfrost / git-import.sh
Last active October 14, 2021 21:32
Move file to another repository while preserving git history
# Copied from https://stackoverflow.com/a/11426261/12560823
# Create git patch from the source repository
cd repository
git log --pretty=email --patch-with-stat --reverse --full-index --binary -- path/to/file_or_folder > patch
# Apply previous git patch to the destination repository
cd ../another_repository
git am --committer-date-is-author-date < ../repository/patch
@diodonfrost
diodonfrost / git-ignore-locally-modifications.sh
Last active July 20, 2021 22:54
Git: ignore files already managed with Git locally
# Tell to Git to ignore localy modifications that will be done on foo.txt
git update-index --skip-worktree ${PWD}/foo.txt
# Display ignored file
git ls-files -v
# Unset the ignore file
git update-index --no-skip-worktree ${PWD}/foo.txt
@diodonfrost
diodonfrost / git-sign-old-commits.sh
Last active July 21, 2021 19:35
Filter only specific commits and sign only them
# Filter only specific commits and sign only them
git filter-branch --commit-filter 'if [ "$GIT_COMMITTER_EMAIL" = "[email protected]" ];
then git commit-tree -S "$@";
else git commit-tree --no-gpg-sign "$@";
fi' HEAD
git push --force