githubteacher / githubfordevelopers-april

GitHub for Developers Training
4 stars 11 forks source link

Distinction between add/commit/push? #116

Closed welchn closed 7 years ago

welchn commented 7 years ago

I understand the metaphor of lining up the family for photos...but it would help to know what happens on a practical/literal level with each command add/commit/push. For each command, where does the file get saved? Locally? In the branch? In the repository?

brianamarie commented 7 years ago

Great question. All of this is being tracked in the .git file, and it's tracking files in three distinct areas: working directory, index/staging area, and history.

When you type git add, it moves it from the working area to the staging area. The practical application of this comes down to having atomic commits, which we'll focus more on tomorrow.

git commit moves things from the staging area to history, where it is now a commit. Commits are far more permanent than things in working or staging, even though the file is saved locally based on what is shown in the working directory.

git push communicates the commits with the remote repository.

Does this help? We will be going into more plumbing fun stuff tomorrow. 😄

welchn commented 7 years ago

Oh...wait...git commit defines what gets published when you say "git push"??

brianamarie commented 7 years ago

git commit defines what gets published when you say "git push"??

@welchn Yes. When you push, the most recent commits on your current branch will be pushed up to the relative branch on the remote.

welchn commented 7 years ago

Thanks Briana, much appreciated!