Search code examples
gitgradlegithubgitignore

Removing files from githubs repository but not locally


So this is my repository: https://github.com/quinnliu/WalnutiQ

I added .gradle & build/ to my .gitignore file. However when I push this change I would like to remove the .gradle file and build/ folder from ONLY my repository and not locally. How can I do this?


Solution

  • Use git rm --cached to remove the files from the index, but not from your working tree. Commit, then push.

    Note that they will still live on in your commit history. Removing them from history entirely is another, more complicated matter.


    $ git clone https://github.com/quinnliu/WalnutiQ.git
    $ cd WalnutiQ
    $ git rm -r --cached build .gradle
    $ ls -a
    ...
    build
    ...
    .gradle
    ...
    $ git status
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #       deleted:    .gradle/1.10/taskArtifacts/cache.properties
    #       deleted:    .gradle/1.10/taskArtifacts/cache.properties.lock
    #       deleted:    .gradle/1.10/taskArtifacts/fileHashes.bin
    #       deleted:    .gradle/1.10/taskArtifacts/fileSnapshots.bin
    #       deleted:    .gradle/1.10/taskArtifacts/outputFileStates.bin
    #       deleted:    .gradle/1.10/taskArtifacts/taskArtifacts.bin
    #       deleted:    build/libs/WalnutiQ.jar
    #       deleted:    build/tmp/jar/MANIFEST.MF
    #