Skip to content

Instantly share code, notes, and snippets.

@vladkens
Created December 2, 2022 19:27
Show Gist options
  • Select an option

  • Save vladkens/5261c703111fd1d0a870c3bf5e53c698 to your computer and use it in GitHub Desktop.

Select an option

Save vladkens/5261c703111fd1d0a870c3bf5e53c698 to your computer and use it in GitHub Desktop.
git sync
#!/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
@vladkens
Copy link
Author

vladkens commented Dec 2, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment