Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grouping files in Git when staging

Tags:

git

Instead of selecting files manually when using git add, is there a way to group these files and assign them a name so all I have to do would be something like git add <groupname>. That would then add all files within that group? Does that feature exist?

Edit: Thanks for all your replies. I know about git add <folder>/*, but what if not all files within that folder are needed? I'm asking so a group of files (let's say 17 files) can be one fork while another group can be from another fork. The thing which bothers me is these files are spread out in different folders so uploading the folder alone won't work. It has to be by file.

like image 495
enchance Avatar asked Oct 21 '25 04:10

enchance


2 Answers

You might consider using a git alias. For example, you can add this to the .git/config file in your repository (or in your ~/.gitconfig):

[alias]
        add-foo = add foo1 foo2 foo3
        add-bar = add bar1 bar2 bar3

Then you can run git add-foo to add the files foo1, foo2, and foo3.

man git-config for more details on git aliases.

Of course, you could always use shell aliases too.

like image 113
jjlin Avatar answered Oct 23 '25 19:10

jjlin


You can add folders as a group, by basically doing git add [foldername]* but no, git doesn't include a functionality to name a group of files. Can you explain exactly why and what the use case going forward would be? Would you want that name to persist between commits? Would you want the name to be stored in the repo and pulled down if someone cloned your repo?

like image 36
mklauber Avatar answered Oct 23 '25 20:10

mklauber