Last active
May 14, 2021 22:27
-
-
Save johnpapa/2501b49c8e57ba893be4dc1607ea73f2 to your computer and use it in GitHub Desktop.
Repo Sync: Refresh/merge your local and origin with the upstream.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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