Skip to content

Instantly share code, notes, and snippets.

@realityforge
Last active February 5, 2019 23:48
Show Gist options
  • Select an option

  • Save realityforge/554fbe5cc516e7da52abe0850c33861f to your computer and use it in GitHub Desktop.

Select an option

Save realityforge/554fbe5cc516e7da52abe0850c33861f to your computer and use it in GitHub Desktop.
Setup a git repository master that points at actual repository
PROJECT_NAME='Schmooze'
PROJECT_SLUG='schmooze'
UPSTREAM_OWNER='Shopify'
LOCAL_OWNER='realityforge'
def mysystem(command, fail_on_error = true)
puts "system (#{Dir.pwd}): #{command}" if @verbose
system(command) || !fail_on_error || (raise "Error executing #{command} in #{Dir.pwd}")
end
mysystem("git clone https://github.com/#{LOCAL_OWNER}/#{PROJECT_SLUG}.git`")
Dir.chdir PROJECT_SLUG
mysystem("git remote add upstream https://github.com/#{UPSTREAM_OWNER}/#{PROJECT_SLUG}.git")
mysystem("git fetch upstream")
mysystem("git checkout upstream/master")
mysystem("git branch upstream")
mysystem("git checkout upstream")
mysystem("git push origin upstream")
`git ls-remote --heads --refs 2>/dev/null`.split("\n").each do |line|
if line =~ /^.*refs\/heads\/(.*)$/
head = $1
next if %w(master upstream).include?(head)
puts "Removing branch #{head}"
mysystem("git push origin :#{head}")
mysystem("git branch -d #{head}")
end
end
`git ls-remote --tags --refs 2>/dev/null`.split("\n").each do |line|
if line =~ /^.*refs\/tags\/(.*)$/
tag = $1
puts "Removing tag #{tag}"
mysystem("git push origin :#{tag}")
mysystem("git tag -d #{tag}")
end
end
mysystem("git branch -d master")
mysystem("git checkout --orphan master")
mysystem("git rm --cached -r .")
mysystem("git add .")
mysystem("git reset --hard")
IO.write("README.md",<<CONTENT)
# Peter Donald's #{PROJECT_NAME} Repository
This repository contains feature branches for the upstream repository: [#{PROJECT_NAME}](https://github.com/#{UPSTREAM_OWNER}/#{PROJECT_SLUG}.git).
It doesn not contain a meaningful master branch.
CONTENT
mysystem("git add -f README.md")
mysystem('git commit -m "Add a README that describes the purpose of the repository."')
mysystem("git push --set-upstream -f origin master")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment