0

I'm trying to create a Github repository for a friend's project (a video game), but can't get the .gitignore file to work properly.

I'm attempting to ignore directories that contain image and audio files, as these aren't best stored on Github.

I've placed a .gitignore file in the root directory of the repository, and put rules in it to ignore the aforementioned directories, but can't push the repo to GH without pushing several thousand PNGs and WAVs.

Do I need to put my .gitignore inside of my .git folder?

Do I need to reinitialize the repository since I added the .gitignore after initialization?

Here is the content of my .gitignore

sprites/images/
sound/audio/
das_j
  • 4,444
  • 5
  • 31
  • 47

2 Answers2

0

There are two ways to solve this:

  1. Put two .gitignore files into sprites/images and sound/audio, both containing just .. The dot matches the current directory and will therefore exclude the two directories.
  2. Put one .gitignore into the root of the project, and add /sprites/images and /sound/audio (each one in it's own line). If you don't put a slash at the beginning, you will also exclude directories like src/sprites/images.
  3. If you want a repository/machine specific gitignore that can not be put under version control, you can add your ignore lines to .git/info/exclude. Paths there will be relative from the project root (like in 2.), but as you can not check this file in and it does not get overridden when pulling, so you can add your personal ignores there.

Git will immediately detect the .gitignore file and any command issued from now on will respect it. Of course, you can commit it too, so every developer has it as well.

If you have already checked in those files, you can use git rm (note that this also removes the files from your disk!) and commit afterwards.

Or, if you want to remove the files from the entire history to shrink your repository size, you can rebase them out. Never rebase and force-push if you don't exactly know what this means for everyone else in the project. It will cause all changes that are not in your local repository (at any other developer and at GitHub) to be overriden.

Community
  • 1
  • 1
das_j
  • 4,444
  • 5
  • 31
  • 47
0
  • git rm -r --cached .
  • git add .
  • git commit -m "Appropriate message"
  • git push origin branch_name
Shravan40
  • 8,922
  • 6
  • 28
  • 48