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 8409125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:49:05+00:00 2026-06-09T23:49:05+00:00

I want to add a file which has a unique file name but a

  • 0

I want to add a file which has a unique file name but a long preceding path (e.g. a/b/c/d/filename.java). Normally I would add this to my repository by doing

git add *filename.java.

However I have also done this before:

git add a/b/c/d/filename*

So I tried to combine the two:

git add *filename*

but this does something weird. It adds every untracked file. I can see possible reasons for failure but they all should occur in one of the previous two commands so I don’t know why this is happening.

My question isn’t so much about how to add a file to a git repository with just its file name (although that would be useful).
My question is what is my misunderstanding of the * operation which makes me think the above should work.

Info:

I am using Git Bash for Windows, which is based on minGW.

  • 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-09T23:49:06+00:00Added an answer on June 9, 2026 at 11:49 pm

    You’re looking at globs
    (not regular expressions, which are a different pattern-matching language), and they’re expanded by your shell, not by git.

    If you want to see how they’re going to match, just pass the same glob to another command, eg.

    $ ls -d *filename.java
    

    vs

    $ ls -d *filename*
    

    (I’ve just added the -d so ls doesn’t show the contents of any directories that match)


    Since you’re using git bash, and it’s possible that glob expansion behaves differently from a regular shell, try

    $ git add --dry-run --verbose -- *filename*
    

    for example: this should show you how it really expands the glob and what effect that has.

    Note the -- … if you’re using globs that might match a filename with a leading -, it’s important to make sure git knows it’s a filename and not an option.

    Unfortunately, this will only show you the files which both match the glob, and have some difference between the index and working copy.


    Answer from author:
    The dry run helped a lot, here is what I found:

    I was forgetting about the bin folder which I haven’t added, so when I performed the dry run I realised it was finding two matches: filename.java and filename.class. When I changed the glob to *filename.j* it worked.

    My next step was to remove the .class and try the command again: it worked! It is still unexplained why git bash added everything when it found two matches… since the dry run behaves differently from the actual run I think there must be a bug, but I think that discussion is to be held elsewhere (unless somebody thinks it isn’t a bug).

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

Sidebar

Related Questions

I want to add one xml file (which has some static data related to
I want to add some more library and helpers file into Pyrocms which is
i want to make an app which can add the file properties of a
I want to add dll file into my project. But i don't know where
I want to add a link to a PDF file but instead of printing
I just want to select the target element which has name attribute value =
I have a java application (jar file) and I want to add some sort
I want to get rid of the big messy edmx file which has caused
I have a configuration file to which I want to add a string, that
i want to add file(photo) to fileupload control in the c#(code behind) thanks

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.