-
Notifications
You must be signed in to change notification settings - Fork 337
Git data model
So what exactly did you do when you clicked the Fork button and then executed the clone command? To explain this, let's first dive into the git's data model and define a few important terms.
Here's a few important terms:
-
repository - the entire contents of a project. In our case, that is the
bootcamp-gitfolder living on your computer, or yourbootcamp-gitrepository on github. -
commit - a snapshot of the entire project at a specific point in time. A commit is usually identified by a random string (called a hash, e.g.
0fb4cde). Each commit encapsulates a set of changes to a set of files (these changes are collectively called a diff). Git gives us a nice way to see exactly what changes we make to files, and commits allow us to revert back to a previous snapshot in history. -
remote - another repository that your project knows about. As an example, if you
cd bootcamp-giton your local copy, and then typegit remote -v, that will list all the remote repositories that your local repository knows about. If you followed our directions, you should have something calledoriginthat points to your repository on github. -
branch - a chain of commits associated together into one logical line of development. By default, all repositories start with a branch called
master. If you are currently onmasterand you make a commit, you've advancedmasterforward by one commit. Engineers typically use abranchto keep all the changes for a new feature together, and then when they're ready, merge back into the mainline. As an example, ourbootcamp-gitrepository looks like this:In this example,
origin/master,master,merge-exercise, andorigin/merge-exerciseare all branches in our repository.masterandmerge-exercisediverged from commit4b40046 - Adding aliases.
When you work with git, there are 4 key environments that you should be aware of.
- local file system - files on your local machine and all their modifications. Changes only in your local file system are not yet snapshotted by git.
-
staging area - changes that will be snapshotted the next time you run
git commit. To add the changes in a file to the staging area, usegit add. -
local repository - local history of all the changes to a project. To create a snapshot, use
git commit, which will take everything from the staging area, and create a commit into your local repository. -
remote repository - history of all the changes to a project, possibly living on an entirely different machine (e.g. github). To sync your local and remote repositories, use
git pushandgit pull.
Here's a diagram that summarizes the environments and the commands to move objects between the environments:
Go back to the main page.

In this example,