Skip to content

Instantly share code, notes, and snippets.

@zachawilson
Last active April 24, 2020 19:32
Show Gist options
  • Select an option

  • Save zachawilson/af78ffd148cdf2a70fb1e3215a580996 to your computer and use it in GitHub Desktop.

Select an option

Save zachawilson/af78ffd148cdf2a70fb1e3215a580996 to your computer and use it in GitHub Desktop.
Makes it possible to share a repo without sharing the history. This will create a branch in the original repo and push to a remote without the history. Inspiration came from: https://stackoverflow.com/questions/19641108/split-git-repo-in-a-squashed-public-and-initial-private
#!/bin/bash
echo MUST be on branch dev-bridge
read -p "Do you want to make branch dev-bridge? Y or N: " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
git checkout -b dev-bridge
fi
read -p "Are you on branch dev-bridge? Y or N: " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo
else
exit
fi
git cat-file -p dev-bridge \
| sed '1,/^$/d' \
| git commit-tree HEAD^{tree} \
| xargs git branch dev
echo branch 'dev' made with no history
echo will merge new 'dev' branch to create a bridge to common history
echo merging...
git merge -s ours dev --allow-unrelated-histories -m 'merge commit to build a bridge to dev'
echo switching to branch 'dev'
git checkout dev
echo now run...
echo git remote add dev -t dev git@github.com:SwitchCaseGroup/__repo__
echo git push dev
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment