I've created a feature branch in an empty Git repo and pushed it to Github. Now I can't create a PR from it as it's considered a "default" branch and there's no master
branch. How can update the repo so that:
master
branch (say, pointing to a commit adding an empty README
file)Any help would be appreciated.
Based on your question, your repository now looks like this:
o
^
feature
and you want to make it look like this:
o-------o
^ ^
master feature
while also making master
the new default branch on GitHub, instead of feature
.
One way to go about it is to create a new "initial" commit on the feature
branch, move it to the beginning of the history and create a new master
branch that points to it.
Here are the steps:
git checkout feature
git commit --allow-empty -m "Initial commit" (you can create the README file here, instead)
git rebase -i --root
# The TODO file will look something like this:
pick 1234abc Adds the feature
pick 5678edg Initial commit
# Move the "Initial commit" line to the top of the file
pick 5678edg Initial commit
pick 1234abc Adds the feature
# Then save and close
At this point, your history will look like this:
o-------o
^
feature
Now, create the master
branch pointing to the commit before the one referenced by feature
:
git checkout -b master feature^
At this point, all you have to do is push master
to GitHub with:
git push -u origin master
Finally, you'll have to go to your repository's settings on GitHub to make master
the new default branch. See GitHub's documentation on how to do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With