Search code examples
gitgithubgit-bashgit-pullgit-stash

how to automate the “stash-and-pull” process? (git)


I create a shell script for run project in a local environment. When running the script I need include if git update also updates my local code with git code before run project.

cd /var/www/html/project && \
    git stash && \
    git pull && \
    git stash apply

There is my try. But problem their when conflict happens no way to change conflict. I need when git stash apply if conflict happen stop a script make way to resolve conflict.


Solution

  • git pull or git stash apply will exit with an error code (= an exit code different from '0') if a conflict occurs.

    In bash, the last command's exit code is stored in $? :

    exitCode=$?
    if [ $exitCode -ne 0 ]; then
        echo "*** something errored"
        exit $exitCode
    fi