Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Alias to chain add, commit, pull, push?

What I am interested in doing is creating an alias that adds all files, commits with a message, does a pull, if there are any conflicts stop and show a list of conflicted files, otherwise push.

I have already found an alias to list conflicted files (git config --global alias.conflicts "diff --name-only --diff-filter=U"), but I have no idea how to integrate the rest of the commands.

Is it even possible to create an if statement in this format?

Pseudo code (multi-line for readability):

git config --global alias.commitall '!func(){ git add -A && git commit -am "$1" &&
             git pull && <conflict detection and possible die of command> &&
             git push; }; func'
like image 459
Richard Parnaby-King Avatar asked Oct 12 '25 06:10

Richard Parnaby-King


2 Answers

There is no need to add a conflict check into the alias. If a conflict is detected on git pull then it automatically echos out the files that have conflicts and stops. This allows the alias to reduced to the following (multi-line for readability):

git config --global alias.commitall '!func(){ git add . && git commit -aqm "$1" &&
    git pull -q --no-progress && git push -q; }; func'

I have added the -q argument to stop the calls from echoing the normal bumpf, but that is preference.

Usage:

git commitall "message goes here"
like image 168
Richard Parnaby-King Avatar answered Oct 14 '25 21:10

Richard Parnaby-King


I think the if potion would look something like this

if [[ -n $(git diff --name-only --diff-filter=U) ]]; then
    git diff --name-only --diff-filter=U                 
else                                                     
    git push                                             
fi         

This answer helped

like image 31
bundacia Avatar answered Oct 14 '25 21:10

bundacia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!