1

Is there a simpler solution than what I have tried?

I want to start a git project with come friends and I have already created a template with all relevant libraries (so they don't have to add them manually). How can I make sure now, that they get the libraries and we can all modify those files without them being pushed, even though they have been changed by each of us?

I found a solution, that should work: I commit and push the template and everyone clones the repo. Then everyone has to do the following:

  1. create a .gitignore including all libraries

  2. remove those files from the repo (git rm --cached <all the lib files>)

  3. add the changes to the staging area (git add .)

  4. pull the remote (with single template commit) and push it again

This should work, but for greater groups it must be done differently, so I wonder whether there is a better way to solve this problem? General descriptions about working in groups with git are desired, too.

NOTE: the mentioned library files stand for various files in our project, that are to be kept in the local repository, but not in the remote one (so they are not pushed/pulled). e.g. .classpath, .profile, /bin, ... (eclipse java project): those files ARE changed locally by each user, but should of course not be pushed back!

Knut Holm
  • 3,988
  • 4
  • 32
  • 54
Fabio
  • 191
  • 12

2 Answers2

2

Usually it's not a good idea to share IDEs configuration, because often have paths (and/or path separators) that works for one developer, but will not for others.

I would then exclude those configuration. Instead of copying tons of files belonging to libraries, have you thought to use maven to manage those?

Said that, if you want to achieve what you're asking for, you should have a look at Subtree to manage those configuration and libraries. In short, you'll have the repository for your project, and subtrees for folders you don't want (e.g. lib/, .classpath, .profile, /bin - seriously you want to version control bin?).

Your friends and whom ever would clone the repository will get all the information to (let git) restore everything.

Give a look at Git Subtree manual page for further information. The same page is available in Italian, as well as the full git manual!

David
  • 2,987
  • 1
  • 29
  • 35
  • So, that's what I understood: I should use maven to store the libs and add it to git as subtree (I am new to git and don't know neither maven nor the subtree tool in git). And I can safely ignore bin/ (I assume .settings/ can be ignored, too). But what shall I do with .classpath and/or .profile? – Fabio Feb 18 '15 at 18:32
  • maven (maven.apache.org) is an apache tool to manage libraries. To keep it short, you write in a xml file the libraries your project needs, and when a developer compiles the project "magically" maven downloads dependencies from the internet. Thus you're not storing libraries in your projects: just using them. Anyhow, to achieve what you asked for, you should use Subtree. If you need help with git, I translated it in Italian and is available on git official website. The Italian manual page for Subtree is at http://git-scm.com/book/it/v1/Strumenti-di-Git-Subtree-Merging – David Feb 18 '15 at 18:39
0

For things like Eclipse project files, you may consider taking a look at

git update-index --assume-unchanged [file]

Documentation can be found here.

Or, see this answer for an alternative solution involving placeholder names for your base lib/ files/directories and having your developers rename them locally to something that is already ignored by .gitignore.

Community
  • 1
  • 1
dbernard
  • 451
  • 3
  • 14
  • I tried this, too, but soon noticed, that this has to be done on all local repositories. And that's exactly what I tried to avoid. (equally applies to `git update-index --skip-worktree [dir or file]`, a stronger flag than the by you mentioned). – Fabio Feb 18 '15 at 18:08