A Git repository is a special database where you want your files and source code to reside and manage by Git. It contains various different versions of your files.

Obtain a Git repository

To obtain a Git repository you can either:

  1. You can take a local directory that is currently not under version control, and turn it into a Git repository, or
  2. You can clone an existing Git repository from elsewhere.

Initialise a Git repository with a local directory

On Unix based systems, navigate to a project’s directory:

cd /Users/username/my_project

Then initialise a Git repo:

git init

This will create a new subdirectory (hidden) named .git that contains all necessary repository files. See The Git directory for more information about .git directory.

Initial commit

At the point by now, your project file is not tracked yet. You will need to do an initial commit to provoke the track:

git add -A
git commit -m "Initial commit"

We will discuss further about Git commands in later topics in Git basics.

Clone an existing directory

If you want to get a copy of remote Git repo, or you have a project you would like to contribute to, you will need git clone command. By running git clone you are not just receive a working copy (if you are familiar with other VCS such as Subversion), but a full copy of all data the server has including every history versions of the project been pull down. This allows that your server disk gets corrupted, you can use nearly any of the cones on any client to set the server back to the state it was in when it was cloned (learn more about distributed VCS in Version Control System).

You clone a repository use the below command in your CLI:

git clone <url>

By default the Git clone will be stored at your current path (pwd).

You can also clone the remote repository into your desired location.

git clone <url> <path>

Git transfer protocol

Depending on how you authenticate with the remote server, you may choose to clone using HTTP(url) or SSH. The previous example uses HTTP protocol, but you may see git:// or user@server:path/to/repo.git, which uses the SSH transfer protocol. You can find more on Git Transfer Protocol


Back to parent page: Git

DevOpsGitGit_RepositorySOFT2412

Reference: