Created
December 2, 2022 19:27
-
-
Save vladkens/5261c703111fd1d0a870c3bf5e53c698 to your computer and use it in GitHub Desktop.
git sync
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # Debug: Print all commands with expanded variables | |
| # set -x | |
| # Get all remote refs & remove outdated local refs | |
| git fetch --all --prune | |
| # Create local copy of remote branch & load latest changes | |
| for rb in `git branch --remotes | grep -v 'HEAD'`; do | |
| lb=${rb#origin/} | |
| echo "$rb -> $lb" | |
| git branch --track $lb $rb 2>/dev/null | |
| git fetch --update-head-ok origin $lb:$lb | |
| done | |
| # Remove all merged local branches | |
| git branch --merged | xargs echo | grep -v '^*\|^main$\|^develop$|^stage$' | xargs git branch -d |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See article on Medium: https://medium.com/@vladkens/git-sync-local-branches-with-remove-origin-afb6a165936e