Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recovering codebase from bare git repository

Tags:

git

I have my codebase in a git repo on my laptop and I setup a bare git repo on an external hard drive for my backup. I successfully pushed my first commit, but noticed my backup repo on my external hard drive does not show the files.

If my laptop crashes, how would I restore my full codebase? Was setting up as bare repo on my external hard drive incorrect?

Thanks Dusty

like image 692
Dusty Avatar asked Aug 02 '15 19:08

Dusty


People also ask

How do you clone from bare repository?

In order to clone your repository to create a new bare repository, you run the clone command with the --bare option. By convention, bare repository directory names end with the suffix . git , like so: $ git clone --bare my_project my_project.

What is a bare repository in git?

What is a bare repository? A bare repository is the same as default, but no commits can be made in a bare repository. The changes made in projects cannot be tracked by a bare repository as it doesn't have a working tree. A working tree is a directory in which all the project files/sub-directories reside.


2 Answers

Change into a new directory and run

git clone /bare/repo/dir.git

substituting the path for the real path of your bare repo. This will clone and check out the latest revision of your repository.

like image 150
Maximillian Laumeister Avatar answered Sep 23 '22 07:09

Maximillian Laumeister


You need to pull to your backup pc in order to receive the committed changes.

You can pull with the command: git pull.

However, it's not explicitly necessary to have a backup pc. After pushing, the changes are stored on both your own pc and the server where your repository is hosted. So you'll allready have two copies of the entire history of your project.

like image 34
Simon Barendse Avatar answered Sep 24 '22 07:09

Simon Barendse