Extremely lazy here, don't like to type too much and specially don't like to remember on which branch I'm in to pull from and push to. Far too often I make the mistake of doing git pull
from a non-master branch, or worse do a push and the target branch is incorrect and I'm left with un-pushed or uncommitted changes.
I created in my .bashrc
the following aliases to help:
alias gitr='git status | grep -Po "On branch \K[^ ]+" | xargs git push origin'
So doing gitr
on any git repo will push the committed changes to the correct branch.
Likewise doing:
alias gitp='git status | grep -Po "On branch \K[^ ]+" | xargs git pull origin'
will pull the latest changes from the correct branch I'm currently in.
Finally this one will commit all local changes as "Cosmetics" and push them to the correct branch:
alias gitcr='git commit -a -m "Cosmetics" && git status | grep -Po "On branch \K[^ ]+" | xargs git push origin'
Is there a way to print all the intermediate commands without doing print in each? and is there a way to make these commands more robust?
UPDATE by print the intermediate commands I mean to show the following to be sure it is running the correct commands:
git status
git pull origin somebranch