SAGARFIVE

1. Introduction

2. Git Basics

3.  Git Terminology

4.  Git Branching

5.  Git - Github

6.  Git Add (Git staging)

7.  Git Commit

8.  Github Advanced

9.  Git Remote

3.5 What is Git bare repository ?

  • A bare repository in Git just contains the version control information and no working files (no tree) and it doesn’t contain the special .git sub-directory.
  • git init one –bare
  • It is used as remote repository, users can connect to that repository and push their changes
  • Bare repo save the files , but do not shows the working tree(project files),
  • But when we clone the bare repository we can see the working tree.

Example/Demo :

(i) First image box :

  • Created bare repo with name git-bare-repo
  • using command with direct init with single command
  • git init git-bare-repo –bare
  • once after repository initialized , listed the files
  • we can see only the version control(metadata or .git folder files ) are showing
  • that means bare repo is like a remote repository host, it won’t save direct files
  • but it saves the files changes information and commits
  • let’s try to try to understand more

(ii) Second image box :

  • changed directory to f drive (acts/login as new user)
  • cd /f
  • cloned the first repo : git-bare-repo (directory path/url on local computer is /c/users/gajan/git-bare-repo)
  • git clone /c/users/gajan/git-bare-repo
  • it worked git repository cloned to f drive
  • moved into the repository : cd git-bare-repo
  • if we try to list it , there is nothing
  • now we try to add some files : touch user1-1.txt
  • Adding to staging area : git add .
  • Commiting : git commit -m “users1”
  • pushing the changes to repo git-bare-repo : git push
  • if we run list : ls , we can see one file user1-1.txt

(iii) Third image box :

  • changed directory to e drive (acts/login as new user)
  • cd /e
  • cloned the first repo : git-bare-repo (directory path/url on local computer is /c/users/gajan/git-bare-repo)
  • git clone /c/users/gajan/git-bare-repo
  • it worked git repository cloned to e drive
  • moved into the repository : cd git-bare-repo
  • if we try to list it , then we can see user1-1.txt
  • now try list file ls at c drive(first image box) , we can see , it only showing the version control(metadata or .git folder files )
  • now we try to add some files : touch user2-1.txt
  • Adding to staging area : git add .
  • Commiting : git commit -m “users2”
  • pushing the changes to repo git-bare-repo : git push
  • if we run list : ls , we can see one file user1-1.txt,user2-1.txt

  • Now moved to f drive
  • pulled the changes from the remote repository, it mandatory if we want to get latest updates
  • git pull
  • if we try to list it , then we can see user1-1.txt, user2-1.txt
  • if we try to list it , then we can see user1-1.txt
  • now try list file ls at c drive(first image box) , we can see , it only showing the version control(metadata or .git folder files )

*** So Git bare repository acts as remote repository, users can connect to that repository and push their changes and pull/get the latest changes, Bare repo save the files , but do not shows the working tree (project files).