THpubs
THpubs

Reputation: 8172

In git, how to commit one file in a branch but ignore in all the other branches?

I have some secure key files which need to be committed only to the staging branch. But I need to ignore them in all the other branches.

In here Using git, how do I ignore a file in one branch but have it committed in another branch? it shows how to commit in one branch and ignore in another. It didn't work for me. I want to commit in one branch and ignore in all the others. How can I do that?

Upvotes: 1

Views: 424

Answers (1)

g19fanatic
g19fanatic

Reputation: 10931

Have the file listed in the .gitignore file in all other branches.

Then in the branch you want it tracked, add a ! before the filename in the .gitignore file. Then manually add the file git add <filename> and it should now be tracked in this current branch but not in the others

Upvotes: 4

Related Questions