Search code examples
gitgithubgit-shell

Do not commit specific changes to the git, but also don't revert them from my local workspace


I have made specific changes to the project configurations to modify my project environment, right now when I do git status I have this my .proj file marked as changed, but I don't want to push this specific file to the github master and I also don't want to revert this files every time before pushing something to github and then setup it again.

What should I do?


Solution

  • You could stash your changes while you're working with the remote:

    # Stage all of your other changes that aren't in the .proj file.
    git add somefile otherfile
    
    # Stash the .proj file changes.
    git stash
    
    # Work with the remote.
    git pull
    
    # Get your .proj changes back.
    git stash pop
    

    Another option is to tell git to consider that file unchanged, regardless of its actual state:

    git update-index --assume-unchanged file.proj
    

    If you change your mind, you can undo this later with:

    git update-index --no-assume-unchanged file.proj
    

    This saves you from having to remember to stash and pop all of the time, but speaking from experience, it also makes it easy to forget that you have local changes and you'll get messed up if there are upstream changes to file.proj.