Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping local changes in a git repo

Tags:

git

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

#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

like image 799
korylprince Avatar asked Jul 18 '12 21:07

korylprince


People also ask

Will git pull remove my local changes?

The reason for error messages like these is rather simple: you have local changes that would be overwritten by the incoming new changes that a "git pull" would bring in. For obvious safety reasons, Git will never simply overwrite your changes.

Does git pull without overwriting local changes?

git pull can change local branches, the local tree and the index. It won't overwrite charges but may do a merge, a rebase or fail if there are conflicting changes.


2 Answers

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).

like image 114
Adam Dymitruk Avatar answered Nov 03 '22 20:11

Adam Dymitruk


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.

like image 37
fork0 Avatar answered Nov 03 '22 19:11

fork0