Skip to content

Instantly share code, notes, and snippets.

@jgwill
Created January 24, 2021 04:54
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 jgwill/c9ea536f4779bdbf108c913359e9fb2a to your computer and use it in GitHub Desktop.
Save jgwill/c9ea536f4779bdbf108c913359e9fb2a to your computer and use it in GitHub Desktop.
Duplicate GIT branching - branch a file to a new one and keep the original using the same data in the repo so they wont be stored twice
#!/bin/bash
dupsrc=$1
newname=$2
branchname="dup-$dupsrc-$newname"
git checkout -b $branchname
git mv "$dupsrc" "$newname"
git commit . -m "dup:mv $dupsrc $newname"
git checkout HEAD~ "$dupsrc"
git commit . -m "restore:$dupsrc"
git checkout -
git merge --no-ff $branchname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment