Skip to content

Commit 8fd07fd

Browse files
authored
feat: Add simple script to sync fork with local branch (#4102)
#### Testing: From the base folder of this repo, run: ```bash ./scripts/sync_fork.sh git@github.com:aseembits93/unstructured.git optimize-_assign_hash_ids-memtfran ``` Check to make sure the only remote is `origin` with: ```bash git remote ``` Check the diff from `main` with: ```bash git diff main ```
1 parent ef68384 commit 8fd07fd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

scripts/sync_fork.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Simple script to recreate a fork branch as a new branch in the current repository
4+
# Usage: ./sync_fork.sh <fork_url> <fork_branch>
5+
6+
set -e
7+
8+
if [ $# -ne 2 ]; then
9+
echo "Usage: $0 <fork_url> <fork_branch>"
10+
echo "Example: $0 https://github.com/user/fork.git feature-branch"
11+
exit 1
12+
fi
13+
14+
FORK_URL="$1"
15+
FORK_BRANCH="$2"
16+
17+
echo "Adding fork as remote..."
18+
git remote add fork "$FORK_URL" 2>/dev/null || git remote set-url fork "$FORK_URL"
19+
20+
echo "Fetching fork..."
21+
git fetch fork
22+
23+
echo "Creating new branch '$FORK_BRANCH' with fork's changes..."
24+
git checkout -b "$FORK_BRANCH" "fork/$FORK_BRANCH"
25+
26+
echo "Removing fork remote..."
27+
git remote remove fork
28+
29+
echo "Done! You're now on branch '$FORK_BRANCH' with the fork's changes. Fork remote has been removed."

0 commit comments

Comments
 (0)