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 trialChris Martinez
11,715 Points"git -add" verbiage: repository/ staging area
the 11-question challenge at the end of "Getting started With Git" asks two questions with identical answers: one asks you to add a file to the repository, and the other asks to add a file to the staging area. Both answers are "git -add" and some file name. is the difference that the latter supposes your file has already been added to the repository --and you are merely staging the changes you made?
1 Answer
Tommy Morgan
Treehouse Guest TeacherYou're right, that's the distinction. git add
really only does one thing - "add stuff to the staging area to prepare it for a commit." But if you're adding a completely new file, there's an extra step that it does - it tells git to "track" the file as being part of your project. This means that git will pay attention to when it changes and make sure you know if you have changes that you need to commit - otherwise git will basically just ignore the file (other than reminding you that it's there when you run git status
).
So you can think of git add
as doing that one thing - "add stuff to the staging area" - or you can think of it as having two different purposes - "start tracking this file" and "add changes I made to this file to the staging area."
Hope that helps.
Jacqueline Boltik
Courses Plus Student 11,153 PointsJacqueline Boltik
Courses Plus Student 11,153 PointsI found this confusing too when I was first getting started with git. Here's how I keep it straight:
$ git add .
Stages your changes but they have not been added to your repository yet
$git commit -m "some message"
commits your changes LOCALLY
$git push
adds changes to your online repository
This is useful because if you don't have an internet connection you can commit a bunch of changes (which technically are local to your machine) and then push them up to GitHub when you have internet again.
I'm not sure if this fully answers your question but hopefully it's helpful!