Search code examples
gitgit-pull

Replace git pull with git up


I use git up in order to avoid merge bubbles, but sometimes I accidentally issue a git pull.

What is the best way to systematically replace a git pull with a git up?


Solution

  • As stated in the git-config documentation, it is not possible to alias an existing git command.

    We can use a bash function that asks you to confirm that you want to actually use the git pull command, and also offers you the opportunity to use git up instead:

    function git() {
        if [[ $@ == "pull" ]]; then
            read -p "Do you want to [p]ull, [u]p or [a]bort? " yn
            case $yn in
                [Pp]* ) command git pull;;
                [Uu]* ) command git up;;
                * ) echo "bye";;
            esac
        else
            command git "$@"
        fi
    }
    

    Example

    $ git pull
     Do you want to [p]ull, [u]p or [a]bort? u
     Fetching origin
     master up to date
    $ git pull
     Do you want to [p]ull, [u]p or [a]bort? p
     Already up-to-date.
    $ git pull
     Do you want to [p]ull, [u]p or [a]bort? a
     bye