1

I know there have been some questions about this. But all I see are using "git -rm --cached", which actually untrack the files at the local side. If I want to remove the file on the remote git repo, what should I do?

When I try to remove untracked file from the Github website, it still creates a commit. Then I fetch and pull from the remote and the untracked file is deleted, which is some local configuration file (e.g. .classpath). I want that untracked file to be removed from remote and it won't affect my next pull. Is there anyway to do that? Or I just have to create another branch or repo?

Finix
  • 115
  • 1
  • 10

1 Answers1

0

When I try to remove untracked file from the Github website, it still creates a commit

That is expected: you cannot remove a file on the remote side without recording that removal (as a commit)

Then a git pull would delete that file locally, unless maybe, as a temporary workaround, you do locally a:

git update-index --assume-unchanged

Yet, the pull might detect a conflict and ask you to resolve it (ie keep the file locally, which means the next git push would recreate that file on the remote side): see more at "Git - Difference Between 'assume-unchanged' and 'skip-worktree'"

I want that untracked file to be removed from remote and it won't affect my next pull.
Is there anyway to do that? Or I just have to create another branch?

Yes, you can have another branch in which that file won't be present.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you! If the upstream has changes, even if I use --assume-unchanged it will still make changes to my local file, right? as the --assume-unchanged flag will be canceled. If so, then the only way is the create a new branch? Can I delete files in the old branch and merge two branches in the upstream? – Finix Jul 16 '16 at 21:47
  • @Finix Yes, creating a new branch is safer than `--assume-unchanged`. You can delete files there and push that new branch to upstream, for upstream to record those deletion. No need to merge. – VonC Jul 17 '16 at 03:39
  • Thank you. But i just did it. Someone needs my code and sync my master branch. He is using a different IDE. So, i'm thinking of removing unnecessary files would be easier for him. – Finix Jul 17 '16 at 04:41
  • @Finix OK, did the merge went well? – VonC Jul 17 '16 at 04:43
  • Yeah, it worked well. Actually, I find I can just delete the files on the upstream old branch. Although this creates commits in upstream, i can just backup files on my side and pull everything. Then put those files into .gitignore. Those files are not needed by my colleague, so it won't create any problem for him. – Finix Jul 18 '16 at 20:34