0

So I accidentally pushed some big files to Github on master branch.

After I did that, I tried doing:

git reset --soft HEAD~2

then I removed the big files, committed, then tried pushing to the remote master, but I get an error saying my local branch is missing commits from the remote master branch.

What should I do? Was there something I should have done instead other than using git reset --soft?

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • *"my local branch is missing commits from the remote master branch"* - is that surprising? You removed two commits by resetting behind them. – jonrsharpe Jul 13 '18 at 22:04
  • 1
    Possible duplicate of [Git: How to rewrite a remote history?](https://stackoverflow.com/questions/26009568/git-how-to-rewrite-a-remote-history) – cgmb Jul 13 '18 at 22:07
  • @jonrsharpe not surprising at all, but the local branch is tracking the remote. They were in sync until I did the reset. Maybe you could answer the question? – Alexander Mills Jul 13 '18 at 23:40
  • You've got the answer: you have to force push if you want to change the history. – jonrsharpe Jul 14 '18 at 07:35
  • @jonrsharpe ok, but was there a better way to do that other than `git reset --soft`...did I really have to add "what should I have done instead?" to the OP to get an answer that included "what I should have done instead"? – Alexander Mills Jul 14 '18 at 17:03
  • What do you mean *"better"*? It's unclear what your criteria are or what outcomes would have been acceptable. For example, does it particularly matter if the offending commits still appear in the history? Do you have some unstated requirement that prevents you from force pushing? – jonrsharpe Jul 14 '18 at 17:05
  • I need to get rid of the accidentally committed large files both locally and on the remote for the branch. – Alexander Mills Jul 14 '18 at 17:12

1 Answers1

2

I'm afraid that git push --force might be needed after you remove the file from the repo history following the "Removing sensitive data from a repository" guide.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111