Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to set up a branch-specific ignoring pattern ?

Jonathan DANA October 7, 2014

Hello,

I'm pretty new to Git (used to work with SVN) so I might be using it the wrong way but here is the issue:

  • I'm making a video-game using Unity3D and the project is subject to teamwork over Git
  • The project contains, at some point, platform-specific files/folders (we use Plugins, scripts, meta files - generated by Unity, which are different from a platform to another - Android, iOS)
  • We would like to have a "clean" branch which will not contains platform-specific files (this way, if we need to handle a new platform - let's say Windows Phone - we can create a new branch from the clean one without having to remove all the unwanted files)
  • We then want one branch for each platform
  • Workers never work directly on the clean branch, only on platform-branches
  • Every platform-branches will be able to merge FROM and TO the clean branch (in order to keep up-to-date the common stuff)
  • That way, the clean branch works as a "filter" that make sure no platform-specific files get out of their branch

Problem is, I can't figure out how to ignore specific files for a branch but not another!

 

Ex: I have added a new plugin in the Plugins/Android folder in the Android branch. But I also have fixed some nasty issue in the common part. I want to push and merge to the clean branch so when iOS workers will pull from the clean branch they will have the fix but not the plugin. Android workers need to have the plugin thought. I would like the Plugins/Android folder to be ignored (not pushed) when I will merge toward the clean branch, but actually pushed when I'll push toward the Android remote branch.

From my search, solutions are either to manually remove files on the clean branch after pushing (waste of time and prone to mistakes) or use a .gitignore. But a .gitignore seems to work across the whole repository so my platform-branches will ignore them too.

Am I missing something ? Please enlighten me on this !

3 answers

2 votes
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 8, 2014

The .gitignore file being tracked like any other is precisely what allows it to be different in different branches. Whenever you check out a branch, the .gitignore will be replaced by the one in that branch and the right version will be used when committing changes. 1.: You create a .gitignore in your working folder and commit it to the branch you have currently checked out. 2.: You switch to another branch. (The .gitignore file will be gone from your working folder.) 3/a.: You create a new, different .gitignore in your working folder and commit it to the branch you have currently checked out. OR 3/b.: Cherry-pick the commit from step 1, make changes to the .gitignore and commit them. 4.: Repeat 2 and 3 as desired for other branches. If you create branches after this is done, the new branch will, at the beginning, have the same .gitignore as the parent branch, but you can make edits and commit them, as needed.

Jonathan DANA October 8, 2014

Thank your for clarifying this. I'll give it a try and come back to mark your answer as the solution.

1 vote
Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 9, 2014

You might have more luck attempting to use subtrees or submodules (I've never used either, so I may be way off). You're going to find that .gitignore won't just prevent those files from being pushed to your core branch, it will also prevent them from being committed to your platform branch.

You might have more luck finding a Unity developer forum and asking for advice about how similar developers handle versioning of platform-specific code.

0 votes
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 7, 2014

The right choice is to use a .gitignore. It can contain different things in the different branches.

 

Jonathan DANA October 8, 2014

From the topics I've read across the web there is no way to create differents .gitignore files for each branch since they all are files tracked by Git, thus one change override the other. Can you give me some details about how you achieve this please?

Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 8, 2014

Please see more detailed answer above.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events