Reputation: 15490
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?
Upvotes: 0
Views: 240
Reputation: 11
Use git rm:
git rm file1.txt
git commit -m "remove file1.txt"
But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:
git rm --cached file1.txt
And if you wand to push changes to remote repo
git push origin branch_name
Upvotes: 0
Reputation: 1329712
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?"
Upvotes: 1