Keeping local changes in a git repo

Say I have a file in a git repo:

#file.py

setting1 = default1
setting2 = default2

<some code>

Now I want to make some local changes that don’t get pushed back into the repo

  • Selectively stage file modifications after rename
  • How can I do “git pull” in multithreading or efficient way?
  • How to split a commit at the middle of a branch history?
  • git: merge file that has been reordered
  • git error: cannot initialize work tree
  • fatal: Not a git repository (or any of the parent directories): .git on every rails command but git commands works fine
  • #file.py - local change
    
    setting1 = mysetting1
    setting2 = mysetting2
    
    <some code>
    

    Say sometime in the future the upstream repo is updated, and I want to pull down their changes without messing up my local settings. I.E a git command I could run that would update the file so that it would be

    #file.py - updated copy
    
    setting1 = mysetting1
    setting2 = mysetting2
    
    <new code>
    

    Is there some way to do this, either with branches or some other git feature where I don’t have to put local settings in a separate file?

    I’ve seen several other questions like this, but they focus on excluding a whole file.

    Thanks

  • Git stops resolving files as renamed after certain number of added/deleted files is reached
  • Bitbucket cannot execute git upload-pack
  • Find all tags at same commit as a given tag in a remote git repository
  • how to git cherry-pick commit declaring our history contains it
  • Should I merge .pbxproj files with git using merge=union?
  • Gitflow with Semver Patch/Minor Update to Earlier Tag
  • 2 Solutions collect form web for “Keeping local changes in a git repo”

    Take a look at git stash. It is also a “whole file” method, but you might find it is flexible enough.

    Otherwise, using git gui and a lot of rebasing (git rebase --interactive) or cherry-picking (git cherry-pick) or just a side branch should help.

    What you are doing is probably changing connection strings and such. It is something that is local to your environment. The proper way to handle this is through smudge/clean scripts. Take a look at the “Git Attributes” chapter in the Pro Git book (freely available).

    Git Baby is a git and github fan, let's start git clone.