Getting Started

It is worth looking at the Learning Git page as this will help you get started and probably explain some concepts better than me, however I want to cover how these commands work.

Creating a Repository

There are two ways to get a Git repository or repo on your computer, which are as follows:

1) Initialise a Directory
  • Either create a new directory or change into an existing one
  • Execute the following: git init

This will have initialised a Git repo in the directory and also created a sub-directory called .git, which is where the repo database is. However this repo is local only, no remote or central server has been setup, see Git Remote for how to do this.

2) Download a Repo

I will use GitLab as an example here, so my repo is located at https://gitlab.com/yyyy/xxxx which is made up but works as an example.

  • Change into the directory that you want to be the parent for where the repo will land
  • Execute the following: git clone https://gitlab.com/yyyy/xxxx.git, this clones the repo into a new sub-directory called xxxx
  • Alternatively execute the following: git clone https://gitlab.com/yyyy/xxxx.git zzzz, this clones the repo into a new sub-directory called zzzz

You are now ready to roll.

States

Files exist in one of four states in Git

Untracked
files not monitored by Git
Staged
also known as "index", marked for inclusion in the next commit
Modified
changed since last commit
Committed
stored in the local repository
Stashed
it is best to read about git stash

Snaphots

.git directory – or repository, pulled from remote server, origin of local project files, metadata and object database

Working directory – single copy, or checkout, of one version of the project, pulled from local .git

When a commit is done staging is pushed to .git