Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing files across branches in Git

Tags:

There are a bunch of files in my project that are sometimes modified but always shared among many different branches. Examples include build scripts, batch files that include paths, etc. Even the .gitignore file itself is an example.

I want this stuff in source control, but I don't want individual branches to keep track of changes to them.

How do you handle this situation?

Do you track everything related to your project in Git? What's your approach to shared objects?

Is .gitignore my only option?

like image 606
Jonathon Faust Avatar asked Jun 03 '11 18:06

Jonathon Faust


2 Answers

Instead of relying on submodules, have you considered git-subtree?

As stated in the documentation:

Subtrees are not to be confused with submodules, which are meant for the same task.

Unlike submodules, subtrees do not need any special constructions (like .gitmodule files or gitlinks) be present in your repository, and do not force end-users of your repository to do anything special or to understand how subtrees work.

A subtree is just a subdirectory that can be committed to, branched, and merged along with your project in any way you want.

Below are some posts giving some feedback and explaining the pros of subtrees over submodules:

  • http://ayende.com/Blog/archive/2011/01/10/the-problem-with-git-submodules.aspx
  • http://ayende.com/Blog/archive/2011/01/10/git-subtree.aspx
  • http://hobocentral.net/blog/2010/07/28/git-subtree/
  • http://h2ik.co/2011/03/having-fun-with-git-subtree/

A very interesting (and somewhat heated) thread, from the git mailing-list, discussing pros and cons of git-subtree and submodule

  • http://amailbox.org/mailarchive/git/2010/7/21/34793
like image 129
nulltoken Avatar answered Oct 09 '22 12:10

nulltoken


Keep your build scripts and batch files in a separate repo?

like image 34
Graham Borland Avatar answered Oct 09 '22 12:10

Graham Borland