Skip to content

Instantly share code, notes, and snippets.

@johnpapa
Last active May 14, 2021 22:27
Show Gist options
  • Save johnpapa/2501b49c8e57ba893be4dc1607ea73f2 to your computer and use it in GitHub Desktop.
Save johnpapa/2501b49c8e57ba893be4dc1607ea73f2 to your computer and use it in GitHub Desktop.
Repo Sync: Refresh/merge your local and origin with the upstream.
function repo-sync {
# ######################################
# link: https://jpapa.me/reposync
#
# What this does:
# [πŸ™] Get the latest for your origin and upstream main branches'
# [𝟚] Make sure your main origin is in sync with your upstream and your local is pushed
# [πŸ›] Checkout your branch and pull the latest'
# [𝟜] Merge main with your branch. This will sync your branch all changes in the upstream
#
# Where do you run this?
# [πŸ™] Open a terminal
# [𝟚] Go to the folder where your local repo is
#
# Steps:
# [πŸ™] Navigate to your Learn or docs repo (learn-pr, learn-m365-pr, azure-docs-pr)
# [𝟚] Run `repo-sync <my-branch-name>`
#
# Usage:
# Option [πŸ™] Get latest for origin and upstream, and push/pull
# repo-sync
# Option [𝟚] Get latest for origin and upstream, push/pull,
# merge upstream master with your local and origin
# repo-sync my-awesome-branch
# Option [πŸ›] Same as #𝟚, but use main branch
# repo-sync my-awesome-branch main
# ######################################
local module_branch=${1:-};
local main_branch="${2:-master}";
echo ''
echo '[πŸ™] Get the latest for your origin and upstream main branches'
echo ' Running steps:'
echo ' git checkout ' $main_branch
echo ' git pull upstream ' $main_branch
git checkout $main_branch
git pull upstream $main_branch
echo ''
echo '[𝟚] Make sure your main origin is in sync with your upstream and your local is pushed'
echo ' Running steps:'
echo ' git pull'
echo ' git push'
git pull
git push
if [[ $module_branch == '' ]]
then
echo ''
echo '[πŸ›] No branch specified, all done'
else
echo ''
echo '[𝟜] Checkout your branch and pull the latest'
echo ' Running steps:'
echo ' git checkout ' $module_branch
echo ' git pull'
git checkout $module_branch
git pull
echo ''
echo '[𝟜] Merge main with your branch. This will sync your branch all changes in the upstream'
echo ' Running steps:'
echo ' git merge ' $main_branch
echo ' git push'
git merge $main_branch
git push
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment