Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use "git --bare init" repository?

Tags:

git

I need to create a central Git repository but I'm a little confused...

I have created a bare repository (in my git server, machine 2) with:

$ mkdir test_repo $ git --bare init 

Now I need to push files from my local repository (machine 1) to the bare repository (machine 2). I have access to machine 2 by SSH. The thing is that I think I don't understand the concept of a bare repository...

What is the right way of storing my code in the bare repository? How can I push changes from my local repository to the bare repository?

Is the right way of having a central repository to have a bare repository?

I'm a little confused with this subject. Please give me a clue on this.

like image 266
André Avatar asked Oct 03 '11 08:10

André


People also ask

What does git bare init do?

git . The --bare flag creates a repository that doesn't have a working directory, making it impossible to edit files and commit changes in that repository. You would create a bare repository to git push and git pull from, but never directly commit to it.


1 Answers

Firstly, just to check, you need to change into the directory you've created before running git init --bare. Also, it's conventional to give bare repositories the extension .git. So you can do

git init --bare test_repo.git 

For Git versions < 1.8 you would do

mkdir test_repo.git cd test_repo.git git --bare init 

To answer your later questions, bare repositories (by definition) don't have a working tree attached to them, so you can't easily add files to them as you would in a normal non-bare repository (e.g. with git add <file> and a subsequent git commit.)

You almost always update a bare repository by pushing to it (using git push) from another repository.

Note that in this case you'll need to first allow people to push to your repository. When inside test_repo.git, do

git config receive.denyCurrentBranch ignore 

Community edit

git init --bare --shared=group 

As commented by prasanthv, this is what you want if you are doing this at work, rather than for a private home project.

like image 74
Mark Longair Avatar answered Oct 25 '22 06:10

Mark Longair