Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Git Basics Getting Started With Git Committing Changes

Travis Lindsey
Travis Lindsey
10,224 Points

git commit -a -m "new message" ....commits all changes. So what happens when i just type git commit -m "new message"?

git commit -a -m "new message" ....commits all changes. So what happens when i just type git commit -m "new message"?

3 Answers

Stone Preston
Stone Preston
42,016 Points

from the git documentation on git commit -a:

git commit -a automatically stage all tracked, modified files before the commit

If you think the git add stage of the workflow is too cumbersome, Git allows you to skip that part with the -a option. This basically tells Git to run git add on any file that is "tracked" - that is, any file that was in your last commit and has been modified. This allows you to do a more Subversion style workflow if you want, simply editing files and then running git commit -a when you want to snapshot everything that has been changed. You still need to run git add to start tracking new files, though, just like Subversion.

so

git commit -a -m "new message"

adds all tracked files to the staging area and commits them in one step.

whereas

git commit -m "new message"

will commit any files that have already been added to the staging area. you add files to the staging area using the git add command.

i generally use

git add -A
git commit -m "some message"

just so I can be sure all files get added to the staging area and get commited

using

git commit -a -m "some message"

only adds the tracked files, so there is a risk of untracked files that you actually want to commit not being commited.

Travis Lindsey
Travis Lindsey
10,224 Points

Thanks. I updated my notes after doing some test commits to make sure I understand.

git commit -m “message about changes” (only for files in staging area)

git commit -am “message about changes” (for all files tracked even if changes are not in staging area)

Li Mbo
Li Mbo
5,096 Points

What do you mean by tracked files?

git commit -a -m "your message" is shorthand. It adds all tracked files and then commits them with your message.

Long way would be to do: git add -A

then: git commit -m "your message"

I have a bunch of aliases for git. Like I use this d = !git add -A && git commit -m

So I just type `git d "my message"

You can add these to you .gitconfig file in your home directory. If you don't see the file. just open up terminal and cd into your home dir. cd / and then do touch .gitconfig

open the file and paste this in

You can change the characters in front of the equal sign to your liking.

[user]
  name = put-your-github-username-here
  email = put-your-github-email-here
[color]
  ui = always
[alias]
  s = status
  p = push origin master
  g = pull
  c = commit -m
  a = add -A
  co = !git checkout -b
  b = branch
  rh = reset -head
  st = status
  d = !git add -A && git commit -m
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
[push]
  default = simple
[filter "media"]
    required = true
    clean = git media clean %f
    smudge = git media smudge %f
[format]
  pretty = \"%C(yellow)%h%Cred%d%Creset - %C(cyan)%an %Creset: %s %Cgreen(%cr)\"
Stone Preston
Stone Preston
42,016 Points

It adds all files and them commits them with your message.

it adds all tracked files, if you added new, untracked files and want them to be committed you will have to add them using git add.

Thank you! I'll update the mistake.

thank you so much