Git ignore files for certain a branch

Hi there!

I have recently run into an issue wher I had some files which I did not want to submit them to github
( i.e Rails initialisers ) and I came across this awesome feature git provides.

Given you have two branches, master and public
When you commit to both
Then you should not see private files in public branch
And you should see private files in branch master

How to accomplish that?

First of all remove root_dir/.gitignore
Then create two text files given any name you like in: root_dir/.git/info/


$ vim.nox .git/info/global

#Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
*swp

This will be your gitignore that is going to be used in any branch.


$ vim.nox .git/info/private

/config/initializers/**/*

This should be what you want to be private. ( i.e not to submit those files to github )

And finally you just have to add global_ignore to be used in all branches and private_files
to branches that you want to be private.

</code>
$ vim.nox .git/config

# To add global_ignore

[ core]
excludesfile = +info/global_ignore

# To add private_files

[remote "origin"]
excludesfile = +info/private_files

[ branch "public"]
excludesfile = +info/private_files

Rationale:

[ remote/branch “branch_name”] might already be defined in your .git/config
if not you just have to add it yourself. I belive this is self explanatory.

Want to learn more?
Here is git docs http://git-scm.com/docs/gitignore.

ABC = Always Be Coding

Leave a comment