Is it possible to run an npm script containing a git push command with the upstream option based on the current branch ?
As an example, I would like to be able to run a command npm run push
.
This command will do something like git push -u origin ${current-branch}
where $current-branch
will be replaced by the local current git branch.
I know that this is possible to achieve it by creating a script, but I would like to know if there is already something provided by npm or git to achieve this with the minimal code requirement.
Thanks for the help !
Solution:
Vlad274's solution works.
Steps:
.gitconfig
on the root of your repositorygit config --local include.path ../.gitconfig
I do this with a git alias, but I assume the same commands would work via npm.
In ~/.gitconfig
:
[alias]
branch-name = "!git rev-parse --abbrev-ref HEAD"
pub = "!f(){ git push -u origin $(git branch-name); };f"