Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8643623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:05:43+00:00 2026-06-12T12:05:43+00:00

Possible Duplicate: Git – Whitelisting files in a complex directory structure I’d like to

  • 0

Possible Duplicate:
Git – Whitelisting files in a complex directory structure

I’d like to have a git repository track only files named e.g. SOURCES while everything else shall be ignored (take e.g. a tree of pdf files where each SOURCES file lists their origins). The simplest shot would have been

*
!SOURCES

in .gitignore. However the exclusion of e.g. A/SOURCES is overridden by the *, requiring me to use git add -f. How can .gitignore be modified to ignore everything except files named SOURCES without requiring a forced add?

edit The solution posted here will not do since the directory structure is not fixed, i.e. new directories containing a SOURCES file should not have to be added to .gitignore by hand…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:05:45+00:00Added an answer on June 12, 2026 at 12:05 pm

    You can’t achieve this using just .gitignore

    Git doesn’t track paths. It tracks objects (~ files) only.

    So, why don’t you reverse the tables:

    git add -f -- */*/SOURCES */SOURCES
    

    or

    shopt -s globstar
    git add -f -- **/SOURCES
    

    Or get out the big guns:

    git add -f -- $(find -type f -name SOURCES)
    

    or even

    find -type f -name SOURCES -exec git add -f -- {} \+
    

    Untested idea Perhaps something like this could be in a pre-commit hook?


    Update An idea for more automation:

    Add this to .git/config

    [alias]
    ac = "!_() { git add -f -- */*/SOURCES && git commit \"$@\"; }; _"
    

    Now, you can just say

    git commit -m 'like you usually work'
    

    and it will automatically add the */*/SOURCES

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Git - Whitelisting files in a complex directory structure I have a
Possible Duplicate: Git undo last commit I have a folder structure like this.. ~/git
Possible Duplicate: Is there any way to clone a git repository’s sub-directory only? clone
Possible Duplicate: Managing large binary files with git The situation is that I have
Possible Duplicate: How to detach the local git repository from its working directory? i'm
Possible Duplicate: Show ignored files in git I have forgotten how I setup my
Possible Duplicate: Using Git with an existing Xcode project Setting up a git repository
Possible Duplicate: Viewing Unpushed Git Commits How do I list all commits which have
Possible Duplicate: Locking binary files using git version control system I am committing a
Possible Duplicate: How do you roll back (reset) a git repository to a particular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.