Shae Kuronen
Shae Kuronen

Reputation: 141

Git Ignore Files per Branch

Goal: only include generated files on specified branches.

Reasons:

  1. Generated files cause conflicts
  2. Deploy via Git is only option in some environments

So, in current workflow, main branch is dev, there are two deployment branches: stage and prod.

What I would expect to work is adding

build/*

[branch "stage, prod"]
    !build/*

to .gitignore or .git/info/excludes would mean that after I run rake build on dev branch, build/ does not show changed files when run git status. On stage and prod branches, build/ would show changed files.

However, all the variations I've tried of the above have not worked.

This seems like pretty typical workflow, is there some git magic I'm missing or how do people deal with this situation?

Upvotes: 7

Views: 9276

Answers (2)

Radon8472
Radon8472

Reputation: 5001

I found an tuturial what should match your request. Basicly it is not possible to make differnt ignores per branch. One way to "fake" this behavoir is:

  1. create different exclude-files per branch (exclude.)
  2. use hooks to create change as simlink always to the exclude of the current branch

Details how to do this cou can find in gitignore per branch - Tuturial

Upvotes: 3

Schwern
Schwern

Reputation: 165606

.gitignore is a file checked into the repository like any other file. Checkout a branch, change .gitignore to how you want it for that branch, and commit it. That change will only affect that branch.

Upvotes: 9

Related Questions