Last active
December 23, 2024 20:40
-
-
Save samuelbezerrab/de5b0aeada1b88f6fd5d99c54841510e to your computer and use it in GitHub Desktop.
Merge remote repo
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
#/bin/bash! | |
# Attention, before running the script, do: `git remote add alternative-repo <REMOTE_REPO>` | |
# Also check branch names on MAIN_REPO_BRANCH and ALTERNATIVE_REPO_BRANCH | |
MAIN_REPO_REMOTE=origin | |
MAIN_REPO_BRANCH=develop | |
ALTERNATIVE_REPO_REMOTE=client | |
ALTERNATIVE_REPO_BRANCH=main | |
## Check if alternative origin was added before everything | |
if ! git remote | grep -q "^${ALTERNATIVE_REPO_REMOTE}$"; then | |
echo "Remote '${ALTERNATIVE_REPO_REMOTE}' does not exists." | |
exit 1 | |
fi | |
## Fetch remotes | |
git fetch $MAIN_REPO_REMOTE | |
git fetch $ALTERNATIVE_REPO_REMOTE | |
## Update main repo branch | |
git checkout $ALTERNATIVE_REPO_REMOTE/$ALTERNATIVE_REPO_BRANCH | |
git checkout $MAIN_REPO_BRANCH | |
git pull $MAIN_REPO_REMOTE $MAIN_REPO_BRANCH | |
## Create the patch file from alternative repo and apply to main repo | |
git diff $MAIN_REPO_REMOTE/$MAIN_REPO_BRANCH $ALTERNATIVE_REPO_REMOTE/$ALTERNATIVE_REPO_BRANCH > changes.patch | |
if [ ! -s "changes.patch" ]; then | |
echo "No changes to patch. Exiting..." | |
rm changes.patch | |
exit 1 | |
fi | |
git apply --index changes.patch | |
rm changes.patch | |
git commit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Para rodar o script direto, sem precisar baixar, use:
/bin/bash -c "$(curl -fsSL https://gist.githubusercontent.com/samuelbezerrab/de5b0aeada1b88f6fd5d99c54841510e/raw/49cf4ad190967b53e5fb7efc18e4a3519777eaab/merge.sh)"