To untrack files in local repository but keep at origin, as our scenario needed; to keep folder or files in git origin repository but untrack any local changes made in this folder, You can use “git update-index –assume-unchanged”. This will enable new developers to get all the files in the repository when cloning. The application can make all the changes it wants in the specified folder, but locally they won’t be committed an pushed to the origin. The only minor problem with this solution is that you have to do this on every new machine that clones the repo. But something positive that comes out of this is that when you need to update files in the untracked folder you can.
1. Preparing the repo
Make sure you add the folder with all the containing files(that you later want to untrack) to the repo. And then commit and push it to your origin. In this example my folder is named Library.
2. Add this folder to .gitignore
And then commit this update. If you need more information about how to use the .gitignore file you can look at git online documentation.
At this stage the folder library and its contents are still tracked by git. Any changes to a file in this folder will therefor be marked as changed still. Lets take care of that next.
3. Untrack files in local repository but keep at origin
Now run the following command to untrack the library folder and its contents:
Make a change to a file in this folder and git will assume it has not been changed, so you won’t commit anything in this folder.
4. Undo this change
Say you need to update a file in the library folder after a while. Then you need only one command to start track this folder again:
5. Make alias of these commands
If you like you can create aliases for these commands to something simpler:
This makes you able to run: