equivalent8
equivalent8

Reputation: 14237

is there any way how to tell git to ignore certain lines of a file?

I'm trying to put my .bashrc .gitconfig and other useful configs on to github (because there are some valuable pieces of code I want to share ) but the thing is I don't want to share certain "valuable informations about me",

so is there any way around to tell git to ignore certain patern or line of a file (for instance in .gitignore? )

note: I figure how to do my bashrc sharing ( I will keep in bashrc public things and move private to bashprofile that I wont share) but I'm kinda wondering how to share my gitconfig (there are some pretty good aliases)

thx

Upvotes: 4

Views: 3940

Answers (3)

Kache
Kache

Reputation: 16747

To answer your question specifically, (which is different from the particular problem you wanted to solve), check out:

How to tell git to ignore individual lines, i.e. gitignore for specific lines of code.

Upvotes: 0

equivalent8
equivalent8

Reputation: 14237

so just for correct closing of this question:

the solutions answered here and in comments worked for my problem (split .bashrc) but for the original question :

is there any way how to tell git to ignore certain lines of a file?

there is no easy way

Upvotes: 2

jw013
jw013

Reputation: 1808

I think it is conceivable to do something of the sort with gitattributes and the smudge and clean filters but it would be messy and probably rather fragile. My method is simply to put things I don't want public in a non-shared ~/.bashrc.local file and source that file inside from the shared .bashrc, e.g.

if [ -r ~/.bashrc.local ]; then
    . ~/.bashrc.local
fi

This also allows me to maintain system/machine-specific configs without screwing up my global .bashrc.

Upvotes: 8

Related Questions