0

I am trying to push my local repository to a github repository but it seems to fail. I have followed the instruction from here and I guess everything seemed fine until the final step:

git push origin master

[remote rejected] master -> master (pre-receive hook declined)

Initially I had 2 issues (at least) as I also had a huge file in a folder (exceed the limitation of 100MB) imposed by github. Anyway I thought I removed the huge file with:

git rm -r --cached model/
git commit -m "Object Detection v0.1"

I could not see the large folder using:

git ls-tree --full-tree -r HEAD

so I guessed I must have removed it.

My remote repository is empty. I checked this answer but for some reason the most popular (not the accepted one) answer refers to gitlab instead of github. And I couldn't find any relevant setting to github neither could I decipher the accepted answer.

So, my questions is how can I push my local repo to my remote repo (I own the remote one)? Also, why I still see error messages about the huge file (I presumed) I had removed? Are there any other actions I should perform to achieve this?

Edit:

To answer why the question here is not a duplicate of mine (or vice versa anyway):
I own the repo so I cannot contact anyone (as suggested in the accepted answer there) and the problem was not on the server side since I actually managed to push a repo without the huge file.

My situation was quite simple (my commits did not contain any real changes in fact) and basically bypassed my problem by creating a new local repo but it's really useful the answer of @Tim.

Eypros
  • 5,370
  • 6
  • 42
  • 75
  • 1
    Possible duplicate of [Git error when trying to push -- pre-receive hook declined](https://stackoverflow.com/questions/7986139/git-error-when-trying-to-push-pre-receive-hook-declined) – tripleee Sep 28 '18 at 07:37
  • Probably the large file is still at fault — you only committed a delete, so when pushing, you would still push a commit including the file (and then a later commit removing it). It would seem like some history re-writing (rebase -i) is in order. – OhleC Sep 28 '18 at 07:38

2 Answers2

3

You didn't actually remove the large folder by making that commit. The file is still part of your history, and that commit is just another version without the large folder. Since you haven't pushed yet, and assuming the latest commit only exists to remove the large folder, I suggest the following steps:

git reset --hard HEAD~1                     # remove latest commit
git rm -r --cached model/                   # remove large folder
git commit --amend 'Object Detection v0.1'  # rewrite initial commit

This assumes that you only had a single initial commit, besides the commit you showed us above which attempted to remove the large folder. If you had multiple commits, then you will have to rewrite history using an interactive rebase (git rebase -i), or possible use filter-branch.

Edit: Based on your comments, you have multiple commits. Then, you can try doing an interactive rebase:

git rebase -i --root

This should bring up an editor in the bash showing you a list looking something like the following:

pick d93jk8f first commit message
pick 2k9vn3d second commit message
pick ekmv098 third commit message
pick f93kl2k fourth commit message

The commits should be listed oldest to newest, from top down. Now change pick to edit, for every commit. To enter into edit mode, type SHIFT + I.

edit d93jk8f first commit message
edit 2k9vn3d second commit message
edit ekmv098 third commit message
edit f93kl2k fourth commit message

Now exit and save: ESC, followed by :wq!

This should start the rebase. Git will now reapply all your commits, and it will pause at each commit. At each pause, you have to remove the large folder, assuming it were there at that point:

git rm -r --cached model/

Then git add the change, commit, and then do git rebase --continue to continue the rebase. Once the whole process is done, that large folder should be completely purged from your history.

Note that I am rebasing starting at the very first commit. If you know, for example, that the large file were committed only three commits ago, then you could have started the rebase via:

git rebase -i HEAD~3

This would let you rewrite only the history going back three commits. But, it seems sensible to just start from the first commit in this case.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

I Have faced this issue and over came like,

! [remote rejected] feature/approve_the_user -> feature/approve_the_user (pre-receive hook declined)

Step 1: Add Semantic Commit Messages. https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716
Step 2: check your commit message properly.
Step 3: Add proper radar or ticket number in your commit message.

Eg: refactor: replaced view modal id from camel to kebab case (rdar://12354889),feat: approve the users of web application. (rdar://99999999)

Kuro Neko
  • 795
  • 12
  • 19