2

I have some files on my local branch that will not be changed from me in the future but they will be changed by the other developer. Currently i have to exclude these files from every push to origin.

What i want is to be able to atleast use gitignore in such a way that i add these files to gitignore and don't have to commit these files because if i commit them the staging build will crash.

I try to add them to gitignore but it asks me to commit and push which i cannot do, also because the other developer has to make changes to these files.

So, i can work with somehow not committing the gitignore file if it just take the burden of having to avoid committing 8-10 other files off my shoulders. Or maybe there is another solution in which i can tell git to ignore these files everytime when it commit? Open to a better solution.

xmaestro
  • 1,084
  • 2
  • 16
  • 44

4 Answers4

4

You can use .git/info/exclude as a local-repo-specific version of .gitignore. For a submodule where .git is a file instead of a directory, you'll need to hut down wherever the .git file points to, then use info/exclude from there.

It's also possible to use some hacks with git update-index --assume-unchanged which is especially useful if the file does exist in the remote repo, but you want some local edits to be ignored. But it's usually better to just ship a .example file

o11c
  • 15,265
  • 4
  • 50
  • 75
  • Not sure why this answer is not popular. +1 to cleaner .git/info/exclude approach. – tom Jun 19 '18 at 06:48
1

You can add your .gitignore to .gitignore file! In that way, your .gitignore file won't be commited. If you use gitignore for other stuff as well, consider using local gitignore file for a directory

  • One advantage of this over my answer is if the `.gitignore` file is inside the directory, you can move the directory around and it will remain ignored. – o11c Jun 12 '15 at 05:36
1

I tried @exussum's solution but that was not working for me since the files were already checked in. Instead i found update-index and add files manually in ignore list.

git update-index --assume-unchanged <file_to_ignore>

This solution will not stand up against a head reset but at least ignores the files for the time being and reduces the risk of checking in unnecessary files.

xmaestro
  • 1,084
  • 2
  • 16
  • 44
0

You can add a user specific .gitignore

Can I make a user-specific gitignore file?

git config --global core.excludesfile $HOME/.gitignore

Then you can populate the .gitignore in your homedir to ignore the files

Edit: note that recent versions of git default core.excludesfile to $XDG_CONFIG_HOME/git/ignore, i.e. $HOME/.config/git/ignore, so you should probably just use that instead of setting it to a different file.

o11c
  • 15,265
  • 4
  • 50
  • 75
exussum
  • 18,275
  • 8
  • 32
  • 65