gitalias
gitalias copied to clipboard
Add 'git cop' alias
Useful alias when you need checkout and pull a remote git branch.
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.
Hi,
Thank you. I usually use it before creating the feature branch and after merging a pull request.
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).