2

I am working on a shared repository and I want to exclude all the files under certain directory just for myself. So I made an entry in $GIT_ROOT/.git/info/exclude

/path/to/folder/

After this I removed the indexes using

git rm -r --cached /path/to/folder/*

A git status after this show a long list of deleted file staged for commit. I commit the changes and till here all is good as any changes made by me are not tracked by git. But I can not push the same to remote as this will mess up other developers working repo. After this If I pull from remote it shows me a merge conflict modified by them/deleted by us. And with git reset --hard origin/<branch_name> It starts tracking the folder again.

Can this not be achieved because I can not push to remote ?

shshnk
  • 1,621
  • 14
  • 26

2 Answers2

1

The thing is that you are committing the files as "removed". That means that anybody that wants to merge your change will get the files removed. Also, if anyone (who hasn't merged your change) modifies those files, when you merge the change from the other developer, you will get a tree conflict. The best you can do under the circumstance is to tell git to not care about those files, while keeping them under the project. This is done with git update-index --assume-unchanged

eftshift0
  • 26,375
  • 3
  • 36
  • 60
1

A more robust solution is to:

  • move that folder outside of your repo
  • add a symlink
  • ignore that symlink with a git update-index --skip-worktree -- mysymlink
  • add a .gitignore inside that moved folder (with a '*' pattern)
  • put a sparce checkout in place in order to not fetch/download that specific folder.

.git/info/sparse-checkout content:

*
!/path/to/mysymlink

(with mysymlink being the name of the folder I want to ignore)

See more at "git assume unchanged vs skip worktree - ignoring a symbolic link"


The OP shshnk mentions in the comments the simpler approach:

I was able to implement it using just sparse-checkout.
Basically I mentioned the name of the folders in the format mentioned by you in .git/info/sparse-checkout file. Now git ignores the files in these folders.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks! I was able to implement it using just `sparse-checkout`. Basically I mentioned the name of the folders in the format mentioned by you in `.git/info/sparse-checkout` file. Now git ignores the files in these folders. This does the job for me. – shshnk Jul 17 '17 at 03:37
  • @shshnk Great! I have included your comment in the answer for more visibility. – VonC Jul 17 '17 at 06:32