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

equivalent8
  • 13,754
  • 8
  • 81
  • 109
  • 1
    Possible duplicate of [Can git ignore a specific line?](http://stackoverflow.com/questions/6557467/can-git-ignore-a-specific-line) – Anil Feb 22 '16 at 17:59

3 Answers3

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.

jw013
  • 1,718
  • 17
  • 22
  • This is the setup I also use. You can then store them locally (or in a private git repo somewhere) for replication elsewhere. – jvc26 Aug 02 '11 at 10:24
  • 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, – equivalent8 Aug 02 '11 at 13:46
  • 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 – equivalent8 Aug 02 '11 at 13:50
  • 1
    It doesn't seem like `.gitconfig` supports including from external sources. Maybe this related [question](http://stackoverflow.com/questions/1557183/is-it-possible-to-include-a-file-in-your-gitconfig) 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 Aug 02 '11 at 14:09
  • jw013 your last link is weary help full, clicking answered because of that. – equivalent8 Aug 05 '11 at 05:36
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

equivalent8
  • 13,754
  • 8
  • 81
  • 109
  • This is definitely not correct closing the question: the answer is *accept*ed but it works around the main answer. This makes it harder to ask/find answer for The Original Question: doing it without outsourcing – Alois Mahdal Mar 22 '12 at 14:46
  • 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 – Alois Mahdal Mar 22 '12 at 14:47
  • 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). – Alois Mahdal Mar 22 '12 at 14:50
  • Actually, there is a way, just as jw013 said: http://stackoverflow.com/questions/16244969 – Kache Apr 29 '13 at 06:32
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.

Community
  • 1
  • 1
Kache
  • 15,647
  • 12
  • 51
  • 79