diff --git a/README.md b/README.md index 7e25e08..351e988 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ npm i -g @xniva/git-shortcuts | `glc` | `git show-branch --no-name HEAD` | Copy and Print the last commit message | | `gsf` | `gcm && gpm && git merge --no-commit --no-ff origin/${featureBranch}` | List the changes of a feature branch w.r.t master - for review | | `gma` | `git merge --abort` | Abort the merge | +| `grb` | `git reset --${hardOrSoft} origin/$(git rev-parse --abbrev-ref HEAD)` | Reset the current branch to its remote equivalent | ### Master branch name is configurable: diff --git a/bin/git_reset_current_branch.js b/bin/git_reset_current_branch.js new file mode 100644 index 0000000..71d5974 --- /dev/null +++ b/bin/git_reset_current_branch.js @@ -0,0 +1,4 @@ +#! /usr/bin/env node +import main from "./../lib/git_reset_current_branch/index.js"; + +main(); diff --git a/lib/git_reset_current_branch/index.js b/lib/git_reset_current_branch/index.js new file mode 100644 index 0000000..a488d16 --- /dev/null +++ b/lib/git_reset_current_branch/index.js @@ -0,0 +1,13 @@ +import runCommand from "./../utils/run_command.js"; + +const main = () => { + let isHard = process.argv[2] === "--hard" || process.argv[2] === "-h"; + + const hardOrSoft = isHard ? "hard" : "soft"; + + runCommand( + `git reset --${hardOrSoft} origin/$(git rev-parse --abbrev-ref HEAD)` + ); +}; + +export default main; diff --git a/package-lock.json b/package-lock.json index 73527ad..61ee971 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@xniva/git-shortcuts", - "version": "1.5.0", + "version": "1.5.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@xniva/git-shortcuts", - "version": "1.5.0", + "version": "1.5.1", "license": "MIT", "dependencies": { "dotenv": "16.4.5", diff --git a/package.json b/package.json index ac760b6..32aa63b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xniva/git-shortcuts", - "version": "1.5.0", + "version": "1.5.1", "description": "Shortcuts for the commonly used git commands", "repository": "https://github.com/kavinkuma6/git-shortcuts", "bin": { @@ -18,7 +18,8 @@ "glc": "bin/git_print_copy_last_commit_message.js", "gr": "bin/git_restore.js", "gsf": "bin/git_see_feature_files.js", - "gma": "bin/git_merge_abort.js" + "gma": "bin/git_merge_abort.js", + "grb": "bin/git_reset_current_branch.js" }, "author": "Kavinkumar R", "license": "MIT",