Skip to content

Instantly share code, notes, and snippets.

@abelflopes
Last active August 24, 2023 17:27
Show Gist options
  • Save abelflopes/7477a74daf748377dda470b7489f43a3 to your computer and use it in GitHub Desktop.
Save abelflopes/7477a74daf748377dda470b7489f43a3 to your computer and use it in GitHub Desktop.
Sourcetree Custom Actions

Sourcetree Custom Actions

This gist is a collection of custom actions for Sourcetree. The actions abstract useful git commands & combinations.

Creating a custom action on Sourcetree

  1. Open sourcetree on a repository
  2. Go to the "OS top bar" > "Actions" > "Custom Actions" > "Edit..."
  3. You should now be on Sourcetree settings with the "Custom Actions" tab selected
  4. Press "Add"
  5. Add the menu caption
  6. Select the script to run (see below examples of scripts)
  7. Enter $REPO on the parameters so that the actions can execute the comments on the repository folder (using $1)
  8. Press "OK"
  9. Done

⚠️ NOTE: make sure your action files have the -rwxr-xr-x permissions. Run chmod +x *.sh on the folder containing the actions files to apply the correct permissions so that they run successfully.

#!/bin/bash
# merges the current changes into the last pushed commit
cd "$1"
git add .
git commit --amend --no-edit
git push --force
#!/bin/bash
# deletes all local branches except develop & master
cd "$1"
git branch | grep -v "develop" | grep -v "master" | xargs git branch -D
#!/bin/bash
# deletes all tags on local & remote
cd "$1"
# Delete All local tags
git tag -d $(git tag -l)
# Fetch remote All tags
git fetch
# Delete all remote tags
# Note: pushing once should be faster than multiple times
git push origin --delete $(git tag -l)
# Delete All local tags
git tag -d $(git tag -l)
# rewrite history
git push --force
#!/bin/bash
# deletes all tags stored locally
cd "$1"
git tag -d $(git tag -l)
#!/bin/bash
# resets/squashes all git history into a sinigle commit
cd "$1"
git reset $(git commit-tree HEAD^{tree} -m "chore: init")
git push --force
#!/bin/bash
# cleans all current changes
cd "$1"
git reset --hard
git clean -fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment