2

In my .gitconfig, I have the following alias:

c = add -A && git commit -m

The idea is to add all changes and commit them. However, I'm not getting success with this because Git is giving me the message error: unknown switch 'm'.

2 Answers2

4

Bad idea. git add or even better git add -p is a great opportunity to review what you did once again before committing.

Anyway, to execute your git alias in a shell you need to use this syntax:

c = !git add -A && git commit -m

Or you could just use git commit -a which seems to be what you want. This will not automatically commit new files but do you really want to commit every single untracked file? Remember that you might have temporary stuff around which is not on gitignore. While it would be easy to undo/amend a commit that accidentally adds this kind of crap, it's better not to commit it in the first place!

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • 1
    I tend to use `git status` followed by `git add -A` followed by `git diff --cached`, myself. Or, `git status` followed by selective `git add`s followed by `git diff --cached`. The first `status` is for thinking about what to add, the `add` adds it, and the `diff --cached` lets me review the diffs before committing (the review is a good time to think about the commit message, too). – torek Mar 11 '14 at 20:15
  • I always use `git status` before I commit, so this isn't an evil idea. – Enrico P. Varella Mar 11 '14 at 20:19
  • `git add -p` has the advantage that you won't just brainlessly scroll through your diff but look at each hunk. That way you easily notice a forgotten `print` and similar things you don't want to commit. Also it lets you keep commits small: Imagine those ugly things (bad code style, messy indentation, etc.) you found while doing something? Yeah, they do not belong into a commit that contains actual code changes. So let's just skip those during `git add -p` (or add and commit them first) – ThiefMaster Mar 12 '14 at 07:27
0

You dont need to do 'git-add', you can pass an -a flag.

git config --global alias.c 'commit -am'

So now c "commi message" should work fine.

If you just want to add it to the config file directly, its just...

c = commit -am

You probably shouldn't adopt this as the way you work regularly though. You should be looking at what you're committing before you commit it.

eddiemoya
  • 6,713
  • 1
  • 24
  • 34