top of page
  • Writer's pictureplusforum. in

01 - How to Setup a Local repository (VCS) in GIT

Updated: Aug 29, 2023

There are two type of Version Control systems, namely Centralized VCS (CVCS) and Distributed VCS. Git is of Distributed Version Control System (DVCS) type.

In a distributed version control system, every user has a copy of the code repository. The repository on the developer's machine is called as Local Repository and the one on a remote server, that is accessible to all team members is called as Remote repository.

Let's start with understanding, how we can create a local Git repository.

  • Creating / initiating a new local repository,

$ mkdir project

$ git init

$ git init <foldername> ... this will create a folder with the given name

and initiate a repository inside that folder.

  • Copy / clone an existing remote repository to local machine.

$ git clone <remote_repo_url> ... Clone a remote repository with other

options.

$ git clone --mirror … this creates a fresh tracking folder with all

remote ref and tags

$ git clone --bare … create a new clone from remote with all tags but

with no future fetch URL associated.

$ git clone <remote_url> --depth <last commits in number>

e.g.

$ git clone <remote_url> --depth 3

For a new local Git repository, the user details have to be configured, so that when a file or set of files are versioned, the version database should be added with user information as who has created the version.

  • To update user name and email address for the user we can use,

$ git config –-local user.name “username”

$ git config –-local user.email “email@address”

and if we want to apply this to all repositories on the machine.

$ git config –-global user.email “email@address”

$ git config –-global user.name “username”

  • To verify the effect of config command, check the file .gitconfig located at user home directory. (/home/<username>/.gitconfig)

  • To add a new file or set of files to the local repository, we can use git add command. This action also indexes the local git repository database.

$ git add … to index all modified / new files to local repo

$ git add <file name> .. index a particular file

  • Move or rename a file in the repository

An existing file in the local repository can be renamed or moved using

git mv command.

$ git mv <file name> <new-file-name> ...With this command the file is

renamed, or moved to a new path with the change getting staged as

well. That means the change is also updated in staging area.

  • To add the version data (hash object) permanently to the local database. Commit a file / object to local repository

$ git commit –m “suitable comment” … changes indexed are

committed to the repository

  • Now to get a list of commands in git one can run the command,

$ git help –a

  • To find difference in the file changes in two versions.

$ git diff HEAD

… or,

$ git diff rev1.0 rev1.1

$ git diff --cached … provides data differences between staging and

repository database.

  • Continuing with the configurations, we can use the config command to set the default branch name. Here in the below command, we are setting the default branch name as 'main'.

$ git config –global init.defaultBranch main

$ git branch -m main … here we are trying to rename the default

branch name to main from ‘master’.

  • To list all versions in local git repository, we use git log command. There are various options with log command that can help to list long or short details of all version in the repository.

$ git log –p … detailed pretty output

$ git log …. List of all commits, version inside git repo.

$ git log --graph --decorate -p ... this will list all version logs with

branch information with color highlighted to show file changes.

  • Get status of repository workspace with command,

$ git status … this command gets information about the status of

workspace, like if there are any files updated / newly create or

deleted and are pending to be added as version updates to the local

depository.

Comments


bottom of page