Git environment
- Git
The Git environment can consist of the following parts:
- Remote repository;
- Working directory;
- Index (staging area);
- Local repository.
Git environment parts
Remote repository
As the name reveals this is a remote repository. The "other" place where the Git directory is stored and optionally shared with others (most of the time another server).
Working directory
The working directory is the location where the uncompressed version of the Git directory (files) is. There are two states the files can be in:
- Tracked files: files that Git is aware of;
- Untracked files: files that have not been added and as such Git has no knowledge of.
Index (staging area)
A file where information is saved about what will go in the next commit.
Local repository
The directory where Git (meta)data is stored. The files are in the .git folder which is in the same directory as the working directory.
Work with Git environment
File-information moves between these parts of the Git environment. Assuming there is a remote repository present, the process starts with cloning the information from the remote repository to the local Git environment. Cloning will create the local repository and the working directory.
Clone a repository
When you clone
a repository the working directory and local repository are created. The default name for the remote repository is origin.
git init
in your local project folder.
Commit changes
When you want to update the remote repository with your changes, these changes move through all parts of your local Git environment and are pushed from the local repository to the remote repository. To add changes to the index use the add
command.
Get updates from a repository
In case there are changes in the remote repository that don't originate from your local repository these changes are not in your local repository. When you want to get updates from the remote repository you fetch or pull the remote repository. When you fetch
, only the local repository gets updated. pull
also updates the working directory by merging the changes.
Summary
So in essence working with Git is a continuous process of:
- get most recent files
- make changes (add/update/delete files)
- stage changes
- commit changes
- push changes