Mina
Mina

Reputation: 85

How to empty the Github repository and send code as a pull request?

There was a empty private repository(which I have access to it) on Github and I push my code into it . Now the owner asked me to empty the repository and send my code as a pull request. can anyone help me to empty repository and send my code as a pull request? thanks a lot for helping in advance.

Upvotes: 4

Views: 3773

Answers (1)

dtc
dtc

Reputation: 1849

I believe I had a similar question... "how do you make a pull request with a fresh new repository?" To do that, my idea is to create two local branches:

  1. branch with updated code
  2. empty branch

So then your question would be "for the empty branch, how do you overwrite the existing code"? Well, you can't. You can only have a remote repo if there's a commit in it. It can't truly be empty. To handle that, just create a single commit with an init. Later, you'll see that I rebase to build off the newly added initial commit.

Solution - This is how I do it assuming two things:

  1. I have existing code I don't want to tamper with
  2. The current branch with the latest code is master.

Command Instructions:

git checkout -b new # assuming "new" is your latest code for pull request to an empty repo
git branch -D master
git checkout -b master # create a fresh master
touch emptyfile; git add .; git commit -m "init commit"
git push origin master
git checkout new
git rebase master # If you're confused by what rebase does, try doing your own little research on it
git push origin new

You can now make a pull request from new into master! All you have to do is delete emptyfile after.

Upvotes: 7

Related Questions