In this question Git command to commit all changes including files removed or created the answer given allows me to add, commit and push all changes made to my master branch in one command with:
git commitall "a message describing what you did"
where commitall is the user defined command:
commitall = "!func(){ git add -A && git commit -am \"$1\" && git push origin master; }; func"
stored in the file ~\.gitconfig under the section [alias].
The problem is that this command only works when I'm positioned in the master branch. How could I generalize this command so it will check in which branch I'm currently positioned and push the changes to that branch?
If you have done (see "git - push current vs. push upstream (tracking)"):
git config push.default simple
# or at least
git config push.default current
Then your git push origin (no branch specified) will always push only the current branch.
If not, replace the git push origin master in your alias with:
git push -u origin \"$(git rev-parse --abbrev-ref HEAD)\"
More at "Git alias on current branch".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With