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'
There is no need to add a conflict check into the alias. If a conflict is detected on git pull
then it automatically echo
s 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"
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
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