-3

I want to commit all of the changes in my repository with one command.

I know I can do it with two—using git add -A and then git commit -a—but, as a wise man once said... why waste time say lot word when few word do trick?.

Is there not an -A option for commit like there is for add?

Brad Turek
  • 2,472
  • 3
  • 30
  • 56

1 Answers1

1

There is not an -A option for commit. Some say it would do more harm than good, committing files you didn't know were there.

However you can still do what you're looking to do: commit it all with just one command.

One command land, here we come!

You can turn any number of commands into one with something called an alias—it's just another name that you can tell git to recognize as a command—you just need to define it. What you name the alias is up to you.

Aliases you could create

  • git ca, if you want brevity; ca standing for "commit all" or
  • git commit-all to match existing git conventions.

You can't make an alias that looks like this

Here's how

To add an alias, open up your user-level git configuration by running git config --global --edit

Then, under the [alias] section, add this line:

[alias]
    ca = !git add -A && git commit -av

The ! allows multiple commands in an alias.

Finally, save and close the file.

A word of warning

Tadah! Now you can run git ca to add and commit all the changes in your repository.

However, using this puts you at risk of committing things you didn't intend to commit, so proceed with caution. Good luck!

Here's a list of other useful aliases you might consider.

Brad Turek
  • 2,472
  • 3
  • 30
  • 56
  • 1
    "Alias names can't have spaces" is a weird way to put it, arguments in general can't have spaces because (un-quoted/-escaped) spaces *separate* arguments. – jonrsharpe Oct 16 '20 at 20:06
  • 1
    Thanks for the feedback, @jonrsharpe. The intended audience might not be experienced enough to realize that; all they know is that they want the same functionality as `add -A`, but in `commit`—which might've lead them to try to use `commit -A` as an alias. – Brad Turek Oct 16 '20 at 20:12