I have forked a project on github and started messing around with it on my own machine, I want to commit the changes I have made back to my fork on github but without commiting the changes I have made to the .cfg file, since this contains things like db password etc
Asked
Active
Viewed 4,831 times
34
-
possible duplicate of [Ignore modified (but not committed) files in git?](http://stackoverflow.com/questions/655243/ignore-modified-but-not-committed-files-in-git) – Cascabel Nov 06 '10 at 17:33
-
There are probably several more duplicates around; you could search for the answer (update-index --assume-unchanged) and find all kinds of things. – Cascabel Nov 06 '10 at 17:35
1 Answers
73
Use this:
git update-index --skip-worktree path/file.cfg
And to restore:
git update-index --no-skip-worktree path/file.cfg
Lastly, if you want to list files that are marked with skip-worktree
:
git ls-files -v | grep ^S | awk '{print $2}'
To simplify, you can make an alias for that in your $HOME/.gitconfig
:
[alias]
ls-ignored-changes = !git ls-files -v | grep ^S | awk '{print $2}'
Then you can type just git ls-ignored-changes
. It even works with auto-completion if you have the git-completion
in place (for bash, tcsh, zsh).

jweyrich
- 31,198
- 5
- 66
- 97
-
Heya, I've already tried that alas, then when I go to commit it's in there ready to commit. Or does that just stop it being pushed when I push? – Gabriel Baker Nov 06 '10 at 17:26
-
2@Gabriel Baker: that's because you already staged the file. Unstage it using `git reset path/file.cfg`. – jweyrich Nov 06 '10 at 17:29
-
1I wish I could give you more than 1 upvote for this super useful piece of info, thanks again! – DrCord Sep 26 '16 at 19:17
-
This is very wrong since Dec 2014. Please see https://stackoverflow.com/a/28268252/1569557 – shadowbq Aug 03 '17 at 12:28
-
@shadowbq You're right. Thank you for bringing this up. I'll investigate an alternative and update my answer accordingly. – jweyrich Aug 03 '17 at 13:07
-
1Please use 'skip-worktree' - https://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree – shadowbq Aug 07 '17 at 11:45
-