Sometime ago I blogged about git sync, an alias I created to concisely pull the upstream repo’s main branch, push that branch to my origin fork, and fetch origin branches to determine which branches have been deleted - likely from merged pull requests. As many repos I work in have changed from master to main, not all of them have yet. Some also use trunk which, personally, I like better but is less common than main.

Rather than separate aliases for each common main branch and given that shell aliases are processed by a linux shell - most often bash - we can use default argument values to run either of the following:

git sync
git sync trunk

Simply run the following command to set the alias to sync main by default, or whichever branch name was specified:

git config --global alias.sync '!git pull -p --ff-only upstream ${1:-main} && git push origin ${1:-main} && git fetch -p origin'