Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace git pull with git up

Tags:

git

git-pull

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?

like image 211
enrico.bacis Avatar asked Jul 14 '15 07:07

enrico.bacis


1 Answers

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
like image 131
enrico.bacis Avatar answered Nov 16 '22 14:11

enrico.bacis