Skip to content

Instantly share code, notes, and snippets.

@nelanka
Last active October 16, 2023 15:45
Show Gist options
  • Save nelanka/ccc550815b27ead95e29 to your computer and use it in GitHub Desktop.
Save nelanka/ccc550815b27ead95e29 to your computer and use it in GitHub Desktop.
Locally untrack files in Git, without using .gitignore

Excluding files from git's changeset

I often find myself leaving out a change set of local changes that I don’t want to check in. In Idea, you can add them to a separate change list of local changes and ignore them from commits. On the command line, you can do a local ignore/untrack of a file, whithout using .gitignore. Useful if your .gitignore is also itself checked into git.

Change the file(s) to be untracked:

nelanka@hydra:/Projects/booking> git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .idea/runConfigurations/Booking_Service.xml
        modified:   .idea/runConfigurations/Sample_Client.xml

no changes added to commit (use "git add" and/or "git commit -a")
nelanka@hydra:/Projects/booking>

nelanka@hydra:/Projects/booking> git update-index --assume-unchanged .idea/runConfigurations/Booking_Service.xml
nelanka@hydra:/Projects/booking> git update-index --assume-unchanged .idea/runConfigurations/Sample_Client.xml
nelanka@hydra:/Projects/booking> git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

Change it back to tracked:

nelanka@hydra:/Projects/booking> git update-index --no-assume-unchanged.idea/runConfigurations/Sample_Client.xml
nelanka@hydra:/Projects/booking> git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .idea/runConfigurations/Sample_Client.xml

no changes added to commit (use "git add" and/or "git commit -a")
@fmtarif
Copy link

fmtarif commented Oct 16, 2023

exactly what I was looking for, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment