Saturday, September 26, 2015

Git Learning Part I - Setting up a repository

Git init command creates a new Git repository. It can be used to convert and existing unversioned project to a Git repository or initialize a new empty repository. 

Executing git init creates a .git subdirectory in the project root, which contains all of the necessary metadata for the repo. Aside from the git subdirectory, an existing project remain unaltered (unlike SVN, git doesnt require a .git in every sub directory) 

The init command variants are 

git init => create git repository at the current path 
git init Initializes the git with an empty directory 
git init —-bare create a shared repository. Repositories initialized with —-bare flag end with .git. For e.g. the bare version of a repository called my-project should be stored in a directory called my-project.git 

Bare flag creates a repository that doesnt have working directory. This makes impossible to edit files and commit in that repository. Central repositories should be always created as a bare repositories because pushing branches to a non-bare repository has the potential to overwrite the changes. We can think of bare as a way to mark a repository as a storage facility as opposed to development environment. This means that virtually for all work flows, the central repository is bare, and developers local repositories are non-bare. 

Below is the most common use case: 

ssh
cd path/repo
git init —-bare my-project.git 

Developers can then clone the repository to create a local copy in their development machine. 

git clone command copies an existing Git repository. This is similar to svn checkout, except that the “working copy“ is full fledged git repository. it has its own history manage its own files and is a complete isolated environment from the original repository.

git config command lets us configure Git installation (or and individual repository) from the command line. This command can define everything from user info to preferences to the behavior of a repository. Some of the configuration options are 

got config —-global user.name
git config —-global user.email
git config —-system core.editor

references:

No comments:

Post a Comment