Search code examples
gitgithubbrancharchive

Exclude folders from Git code search / create archive branches


TL;DR version

Files in a certain folder are cluttering my search results when I search on GitHub. I only need those files for their archivational purpose, so although I don't want to remove them, I thought I could move them to a separate branch periodically to clean up this folder in master.

Question is how to do that in such a way that it's easy, repeatable, and doesn't pollute my history too much.

Context

My (our) situation, we have a git repository that holds the current state of our data model. So it has a file called TAB_ORDER.sql, which contains the create table statement for creating the table. These files are basically generated using RedGate Schema compare.

In addition, the repository contains migration script that help us deploy changes. A pull request is expected to contain the change to the object file, as well as a migration to make it happen on the live database. So to add a column to that table, in a single PR, I would add a migration file with an alter table TAB_ORDER statement for adding a column, and I would modify TAB_ORDER.sql so the create statement in there represents the new state of the table, including the new column.

So far so good.

The problem

The problem is, I love to use GitHub to search for uses of certain database objects, because it's fast, and it allows me to search through all our repos. But my searches are polluted by all the migrations scripts. Ideally I want to exclude those from the search, but GitHub doesn't support that, and it doesn't look like it will any time soon.

So I have basically two options, apart from just sticking with it:

  • Delete the migration scripts completely.
  • Keep the migrations in a separate branch, but not in master.

I would prefer the latter, so I can actually keep my migration scripts, and search those if I want to. Deleted files are kept in history, of course, but it's not easy to find those anymore, so keeping them undeleted has preference.

My solution (that I need help with)

How can I easily move these migration scripts to a separate archive branch. Given the fact that I want developers to create a single PR with the migration and the modification, that archiving would be a separate process that I could do periodically, but I don't really know a good way to "move" files from master to a branch, basically.

Alternative solutions are welcome too, of course.


Solution

  • Turns out you actually can exclude paths from the search results. I couldn't figure it out before, and when searching I only found evidence that it's not possible. But a colleague (thanks, Wes!) just pointed out to me that you can simply add -path to the search query to filter out a folder.

    So to search for the use of TAB_ORDER in all repositories, except in the Migrations folders (fingers crossed that other repos don't have relevant search results in a folder with the same name), I can simply search for this:

    TAB_ORDER -path:Migrations
    

    Looks like the path has to be the full path (relative to the repo), so if you have a path a/b/c, you can add -path:a, or -path:a/b/c, but not just -path:c.