Ignore pushing directory, but still track in Git
Is there any way to ignore a directory when you push remotely? The catch is I don’t want to ignore it. I still want to track the directory, and have local commits and branches for it. Say, I’m working on a project that relies on a database. This project does not have transitional schema or anything. It is populated with data for testing. I have a symbolic link for MySQL’s folder/files (MyISAM MYD/MYI) to my local repository. I want the database and the commits in sync, but cannot push the database (or assets, etc). I tried a submodule, with no avail – the parent repo ignores the child submodule changes. How would I go about this? Example structure:
/repo/my-project <– git repo
/repo/my-project/src <– push commits related to this section to a remote repo that uses this as the root directory
- git automatic files tracking
- git: setting a single tracking remote from a public repo
- Are there different meanings to the concept of 'tracking' in git?
- tracking remote repository from another remote in git
- My local git tracking branch isn't working properly. I need advice on how to set it up
- Is version control (ie. Subversion) applicable in document tracking?
/repo/my-project/mysql <– track these but don’t push them
3 Solutions collect form web for “Ignore pushing directory, but still track in Git”
When you push a given branch, you push the commits on that branch. If those commits include the contents of a given directory, you will be pushing that content.
Your two options are:
Keep that directory on a branch (or branches) which are never merged into the branches you push. You can still merge other changes into that branch freely, of course.
Keep that directory in a separate repository. The easiest approach would then be to symlink that directory to the real location of the repository, and ignore the path. (You can ignore it in
.git/info/excludesto avoid even publishing that gitignore entry.) More detailed instructions:
cd path/to/project # move the directory outside your project mv database-dir .. # add an ignored symlink to it echo "database-dir" >> .git/info/excludes ln -s ../database-dir database-dir # create a new repo in the directory to track it cd ../database-dir git init; git add .; git commit
It’s possible to ignore files from inclusion to your repository by adding them to the .gitignore file — but I don’t think that’s what you want.
Why not track the database in a separate repository without a remote branch?
(Note that if you never push remotely, you wont have a backup if your hard drive fails.)