Skip to content

Instantly share code, notes, and snippets.

@vitaliy-kravchenko-dev
Last active April 30, 2019 10:25
Show Gist options
  • Save vitaliy-kravchenko-dev/08f19b73fab471c6a65498832e4a8ece to your computer and use it in GitHub Desktop.
Save vitaliy-kravchenko-dev/08f19b73fab471c6a65498832e4a8ece to your computer and use it in GitHub Desktop.
Git & NPM- Useful commands

Clean up already merged branches

Local cleaning

git branch -r --merged | egrep -v "(^\*|master|dev|release|staging)" | xargs git branch -d

Remove local branches which don't have remote origin

git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done Found on Stackoverflow - https://stackoverflow.com/a/33548037

Remote delete

git branch -r --merged | egrep -v "(^\*|master|dev|release|staging)" | sed 's/origin\///' | xargs -n 1 git push --delete origin

Scripts

Prevent increasing verion of package if nothing changed

"scripts": {
    "preversion": "VERSION=$(node -p \"require('./package.json').version\");if [ \"$(git log -1 --pretty=format:%s)\" != \"$VERSION\" ]; then echo Version checks passed. ; else echo Error: Not new commits found. ; exit 1 ; fi",
    "version": "",
    "postversion": "git push"
  }  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment