4

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

1

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

5 Comments

This is the setup I also use. You can then store them locally (or in a private git repo somewhere) for replication elsewhere.
nice solution, but what about files like .gitconfig, I have there lot of aliases, and I was googling for something like ".gitaliases" but it seems like git isn't suporting anything like it,
basicly I want to just push my [alias] section on github from .gitconfig, and keep my private info inside [user] section hidden.. so can I split it up somehow? ...but want to keep those setings inside .gitignore global, only solution I fond is for using different settings inside local repositories
It doesn't seem like .gitconfig supports including from external sources. Maybe this related question can give you some ideas. One of the answers mentions using gpg in the smudge/clean filters, but if you don't need that you could come up with some sed/cat filter to extract / concatenate a whole section, which shouldn't be too difficult.
jw013 your last link is weary help full, clicking answered because of that.
2

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

4 Comments

This is definitely not correct closing the question: the answer is accepted but it works around the main answer. This makes it harder to ask/find answer for The Original Question: doing it without outsourcing
I suggest altering this question to a .bashrc or .bashrc-and-likes -specific one. That will make it a perfect Q+A pair, without confusing those who need to find real "line-level" solution
Additionally, I'd ask the original question (mentioning this one to avoid confusion and duplicate answering) separately. The fact that it will probably remain unanswered is acceptable (by the way, never say never, maybe Git 2.0 will support it).
Actually, there is a way, just as jw013 said: stackoverflow.com/questions/16244969
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.