Skip to content

Instantly share code, notes, and snippets.

@leogdion
Last active December 8, 2021 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leogdion/677dff5ac5f8e604b04428a37f00a3fb to your computer and use it in GitHub Desktop.
Save leogdion/677dff5ac5f8e604b04428a37f00a3fb to your computer and use it in GitHub Desktop.
#!/bin/bash
DEST_REPO=$1
DEST_BRANCH=$2
MESSAGE=$(git log -1 HEAD --pretty=format:%s)
SOURCE_BRANCH=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
git remote add destination $DEST_REPO
git fetch --all
git checkout -b destination-merging SOURCE_BRANCH
git reset --soft destination/$DEST_BRANCH
git commit -am "$MESSAGE"
git rebase -Xtheirs destination/$DEST_BRANCH
git checkout -b destination-branch destination/$DEST_BRANCH
git merge -Xtheirs --squash destination-merging
git commit -am "$MESSAGE"
git push destination HEAD:$DEST_BRANCH
git branch -D destination-branch
git branch -D destination-working
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment