Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git command to add, commit, and push to the correct branch

Tags:

git

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?

like image 883
Gabriel Avatar asked Jul 26 '26 14:07

Gabriel


1 Answers

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".

like image 74
VonC Avatar answered Jul 28 '26 06:07

VonC