Altijd in beweging...

Technische ontwikkeling staat nooit stil

Git environment

March 10, 2020
  • Git

The Git environment can consist of the following parts:

  • Remote repository;
  • Working directory;
  • Index (staging area);
  • Local repository.

Git branch 2

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).

Although most of the time I have a remote repository set up (for backup and/or sharing) it's possible to discard this part and setup Git only locally. That way you still have the commit history to work with.

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. Clone a remote repository

In case you only want the local Git environment and not a remote Git environment then the starting point is not a clone of a remote repository but a 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. Commit changes

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. Get updates Get updates

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

Git branch 12

Previous article Git basic concepts