MeltingDog MeltingDog - 3 months ago 10
Git Question

How can I delete a file from GitHub?

I'm following a tutorial on how to use Git. I'm up to the part where I am to push files to a newly created GitHub repo. However I am getting the error:

Updates were rejected because the remote contains work that you do not have locally.


I'm guessing this was because the GitHub repo had a
readme.md
file in it, provided by GitHub, and my local didn't. So I deleted that file. However I still cannot push. I'm still getting the same message.

I'm guessing this is because I have to somehow 'push' the changes (the deleting of read me) on the remote repo?

Would anyone know how to go about that?

Answer

So I deleted that file. However I still cannot push. I'm still getting the same message.

That deletion has created a new commit that you don't have locally.
The issue is not the presence or absence of files, it is the presence of different history (set of commits) between your local repo and the remote repo.

Set your local configuration with:

git config --global pull.rebase true
git config --global rebase.autoStash true

Then simply git pull.

Any local work in progress will be stashed, your own commits rebased, your work re-applied. You can then review, add, commit and push.

That combination (pull.rebase + rebase.autostash) is available since Git 2.6 (Sept. 2015): see "Can “git pull” automatically stash and pop pending changes?"