-
Notifications
You must be signed in to change notification settings - Fork 341
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-git
folder living on your computer, or yourbootcamp-git
repository 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-git
on 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 calledorigin
that 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 onmaster
and you make a commit, you've advancedmaster
forward by one commit. Engineers typically use abranch
to keep all the changes for a new feature together, and then when they're ready, merge back into the mainline. As an example, ourbootcamp-git
repository looks like this: In this example,origin/master
,master
,merge-exercise
, andorigin/merge-exercise
are all branches in our repository.master
andmerge-exercise
diverged 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 push
andgit pull
.
Here's a diagram that summarizes the environments and the commands to move objects between the environments:
Go back to the main page.