gitalias icon indicating copy to clipboard operation
gitalias copied to clipboard

Add 'git cop' alias

Open OKTAYKIR opened this issue 6 years ago • 3 comments

Useful alias when you need checkout and pull a remote git branch.

OKTAYKIR avatar Feb 15 '19 08:02 OKTAYKIR

Thanks!

How often do you do this command?

Would you be nearly equally happy with co-p? Your idea for composing aliases could be powerful and useful to many more aliases.

joelparkerhenderson avatar Feb 15 '19 22:02 joelparkerhenderson

Hi,

Thank you. I usually use it before creating the feature branch and after merging a pull request.

OKTAYKIR avatar Feb 17 '19 13:02 OKTAYKIR

Interesting suggestion! I use something similar, git copum for git checkout main && git pull upstream main. That said some repos use master instead of main so I actually have git-copum as a shell script which first detects the branch (main or master) and then runs checkout + pull upstream.

#!/bin/zsh

has_main=$(git branch -a --format '%(refname:short)' | grep -cEw '^main$')
has_master=$(git branch -a --format '%(refname:short)' | grep -cEw '^master$')

if [[ $has_main == 1 ]]; then
    git checkout main
    git pull upstream main
elif [[ $has_master == 1 ]]; then
    git checkout master
    git pull upstream master
else
    >&2 echo 'Unable to find either `main` or `master`'
    return 1
fi

I have a similar version for just pum doing git pull upstream (main|master).

nicolasff avatar Jan 15 '22 01:01 nicolasff