Your Location is: Home > Git

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

From: United View: 4059 Brad Turek 

Question

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?

Best answer

There is not an -A option for commit. Some say it would do more harm than good, committing files you didn't know where 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.

You could create

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

With git aliases, you can't do

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.