Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Development Tools Git Basics Getting Started With Git Committing Changes

Maximiliane Quel
PLUS
Maximiliane Quel
Courses Plus Student 55,489 Points

when to use -a flag

Hi guys,

the code challenge following this video asks us to commit changes twice the first time using the -a flag leads to an error the second time when it asks to commit changes made to the same file it insists on the flag.

Does that mean that you use the flag only when you commit changes one after the other to the same file or wouldn't it be a good idea to always commit all changes? I'm not sure I understand why it was wrong the first time and imperative the second ...

Thanks in advance for explaining.

3 Answers

Maximiliane Quel
PLUS
Maximiliane Quel
Courses Plus Student 55,489 Points

I just found this and I guess it answers the question: why you don't need -a when committing staged files. for anyone that was wondering the same thing. however feel free to add any additional wisdom below ;0)

Tommy Morgan
STAFF
Tommy Morgan
Treehouse Guest Teacher

Maximiliane Quel -

So, git has this notion called the "staging area." Think about it kind of like a suitcase - when you want to pack up to go on a trip, you put everything you want to take with you into the suitcase. When you want to make a commit to a git repository, you put all of the changes you want in that commit into the staging area. Make sense?

The -a flag is a shortcut that basically means "put all of my changes into the staging area." If you don't use that flag, git will only try to commit stuff that you've already put into the staging area (which you do with the git add command) - or if the staging area is empty, it will give you an error message.

So essentially, if you want to have careful control over which of your changes get added to a commit, add them individually to the staging area and then commit without the -a flag. If, on the other hand, you want the commit to include ALL of your current changes, whether they're currently in the staging area or not, use the -a flag.

Hope that helps.

Maximiliane Quel
Maximiliane Quel
Courses Plus Student 55,489 Points

Thank you very much for taking the time to go over it in detail. It does make sense and I think the analogy is good. Getting further through the course also made it clearer.

I'm curious about one other thing if you don't mind. When it comes to workflow how exactly does that work. Do you code in your editor switching into the console when you make your submits etc or do you use an integrated solution such as offered with coda? I assume you do your other coding in a text editor? Just curious.

Tommy Morgan
Tommy Morgan
Treehouse Guest Teacher

I do all of my coding in vim, for which there's a nice plugin named Fugitive that integrates with git. That works really well for the basic stuff, like we cover in this course - sometimes I need to do more advanced things, though, or I just happen to have a console window open, and in those instances I'll use the command-line.

How you interact with git really just boils down to personal preference, so definitely try out different ways until you find something you really like. We just chose to teach the console commands for this course because it gives a really clear view of what's going on "behind the scenes" and it works relatively the same on every computer.

Maximiliane Quel
Maximiliane Quel
Courses Plus Student 55,489 Points

Again thanks for a quick reply. I was just being nosy ;0). As you said there are many different solutions and everybody does have there preferences, so it's always interesting to see what other people use and like.

I think it's good that the course is done on the command line because we should be getting used to using it or at least have that option of getting familiar with it. Even though I have to admit that opening the terminal still makes me feel as nervous as if I was asked to diffuse a bomb. Thankfully you knew what you where talking about.

I will see you on another course I am sure.