How can I commit everything that's changed in my git repo with just one command? [duplicate]
Asked Answered
F

1

-2

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?

Fink answered 16/10, 2020 at 19:58 Comment(1)
It was my first hit for git add and commit everythingOckham
F
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.

Fink answered 16/10, 2020 at 19:58 Comment(2)
"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.Ockham
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.Fink

© 2022 - 2024 — McMap. All rights reserved.