0

I recently added a repo on https://github.com/me/myRepo. Then locally (on my computer) I removed a file rm ~/myDir/myFile I am trying now to make it disappear on github without success. I did:

cd ~/myDir git rm myFile (I had already remove the file physically) git add -A git push 

But the file is still there...

When I do

git commit -a git push 

This is not working, I get

statquant@euclide:~/.vim$ git commit -a # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # (commit or discard the untracked or modified content in submodules) # # modified: bundle/Align (untracked content) # modified: bundle/Clang_Complete-Pathogen (untracked content) # modified: bundle/Vim-R-plugin (untracked content) # modified: bundle/bash-support.vim (untracked content) # modified: bundle/git (untracked content) # modified: bundle/nerdtree (untracked content) # modified: bundle/perl-support.vim (untracked content) # modified: bundle/snipmate (modified content, untracked content) # modified: bundle/tasklist (modified content) # no changes added to commit (use "git add" and/or "git commit -a") statquant@euclide:~/.vim$ git push To https://github.com/statquant/.vim.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/statquant/.vim.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details. 
2
  • As stated by the error message, your push was rejected. Do a git pull first. Commented Feb 17, 2013 at 12:53
  • worked ! thanks mate, I'll accept as soon as I can Commented Feb 17, 2013 at 12:55

4 Answers 4

3

You have to commit the deletion before pushing:

rm file git commit -a git push 
Sign up to request clarification or add additional context in comments.

4 Comments

Any references for your statement?
He might have other uncommitted changes besides the deletion. He might not want to commit them at the same time.
What you suggest did not work I edited my message... not sure why though
See my comment on your question.
1

You are missing to commit the changes.

$ cd ~/myDir $ git rm myFile $ git commit -a -m "Your commit message" $ git push origin master 

Comments

0

If you're saying that you want to remove the file from all of the history on github, read this. Otherwise, yeah commit the change like everyone else has said.

Comments

0

git rm <file>

git commit -m "deleted a file"

git push

However, the file is still available through the history, e.g. through a cherry-pick of the commit that put it in the repository in the first place.

For sensitive data, or perhaps code you want to ensure never ever makes its way back into your project, it is recommended to 'rewrite' an entire branch's commit history with git filter-branch.

WARNING: this will change the SHA-1 hash of ALL the commits in the branch from the point the (now removed) file was originally added, so you will not be able to easily push and distribute the rewritten branch on top of the original branch. If it is a very recent commit you are removing, then this approach may not cause a problem for others.

git filter-branch --index-filter 'git rm --cached --ignore-unmatch <file>' HEAD

To be able to use options like filter-branch, you should always create, code in, and commit to, your own branch within a repository.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.