Nik
Nik

Reputation: 9452

Clever git add command

Imagine that we have edited file foo.c.

It is possible to write git add foo*, but what if I want to write git add *o* to reduce keystrokes? Is there any way to get this behavior in git CLI interface?

Upvotes: 0

Views: 85

Answers (2)

Tim
Tim

Reputation: 43354

What you are asking for actually works.

$ touch foo.c
$ touch bar.c

$ git status
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   bar.c
#   foo.c

$ git add *o*

$ git status
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   foo.c
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   bar.c

Upvotes: 2

Roberto Reale
Roberto Reale

Reputation: 4317

Is is already possible, if you work in a POSIX-compliant shell (like Bash). Indeed, it is the shell itself and not the git client that expands foo* or *o* to foo.c.

But be aware that, should you happen to have another file matching the globbing pattern (e.g. not-to-be-added.c), it would be added as well.

Upvotes: 2

Related Questions