A set of scripts to keep your branches synchronized in a large monorepo development environment.
These scripts help automate Git branch management when working with a branching strategy that requires:
- Keeping an epic branch in sync with main
- Ensuring feature branches include changes from their parent epic branches
- Handling potential merge conflicts safely
-
Clone or download these scripts into your repository's
/scripts
directory -
Make the scripts executable:
chmod +x /path/to/scripts/branch-sync.sh
-
Set up Git aliases for convenience:
# Add commonly used epic branch git config --local alias.sync-gs '!bash $(git rev-parse --show-toplevel)/scripts/branch-sync.sh --epic gs-maker-checker/ENG-32296' # Add custom epic branch sync git config --local alias.sync-with '!f() { bash $(git rev-parse --show-toplevel)/scripts/branch-sync.sh --epic "$1"; }; f'
git sync-gs
git sync-with feature/my-epic-branch
bash scripts/branch-sync.sh --epic feature/my-epic-branch --main develop
The branch sync process:
-
Stashes any uncommitted changes to preserve your work
-
Fetches the latest changes from the remote repository
-
Updates the epic branch with changes from main:
- Checks out the epic branch
- Merges main into the epic branch
- Pushes the updated epic branch
-
Updates your feature branch:
- Returns to your original branch
- Merges the epic branch into your feature branch
- Pushes your updated feature branch
-
Restores your uncommitted changes
If merge conflicts occur:
- The script will notify you with clear instructions
- You'll remain in the conflicting branch to resolve issues
- Your original changes will be safely stashed
- After resolving conflicts, you can continue by running the script again
The branch-sync.sh script supports the following options:
Usage: ./branch-sync.sh [options]
Options:
-e, --epic BRANCH Specify the epic branch name (REQUIRED)
-m, --main BRANCH Specify the main branch name (default: main)
-h, --help Show this help message
If you get "permission denied" errors, make sure the scripts are executable:
chmod +x scripts/branch-sync.sh
If pushing fails, the script will provide instructions. Common solutions:
- Pull the latest changes with
git pull --rebase origin <branch-name>
- Resolve any conflicts and try again
If merge conflicts occur:
- Open the conflicting files in your editor
- Resolve the conflicts manually
- Add resolved files with
git add <files>
- Complete the merge with
git commit
- Run the sync script again