What is a bare git repository?

By Jon Saints - 26 Jan 2011

UPDATED: 5/30/2015 - Fixed inaccurate description of where files are stored in bare git repositories and updated explanations of both bare and no-bare repositories

What is the difference between a repository created using the git init command and the git init --bare command?

Repositories created with the git init command are called working directories. In the top level folder of the repository you will find two things:

A .git subfolder with all the git related revision history of your repo
A working tree, or checked out copies of your project files.
Repositories created with git init --bare are called bare repos. They are structured a bit differently from working directories. First off, they contain no working or checked out copy of your source files. And second, bare repos store git revision history of your repo in the root folder of your repository instead of in a .git subfolder. Note… bare repositories are customarily given a .git extension.

Why use one or the other?

Well, a working repository created with git init is for… working. It is where you will actually edit, add and delete files and git commit to save your changes. If you are starting a project in a folder on your dev machine where you will add, edit and delete files of your project, use “git init”. Note: if you git clone a repository you will be given a working repository with the .git folder and copies of the working files for editing.

A bare repository created with git init --bare is for… sharing. If you are collaborating with a team of developers, and need a place to share changes to a repo, then you will want to create a bare repository in centralized place where all users can push their changes (often the easy choice is github.com). Because git is a distributed version control system, no one will directly edit files in the shared centralized repository. Instead developers will clone the shared bare repo, make changes locally in their working copies of the repo, then push back to the shared bare repo to make their changes available to other users.

Because no one ever makes edits directly to files in the shared bare repo, a working tree is not needed. In fact the working tree would just get in way and cause conflicts as users push code to the repository. This is why bare repositories exist and have no working tree.

To summarize

I use a working directory created with git init or git clone when I want to add, edit and delete files in myproject locally on my dev machine.

When I am ready, I share my local changes with a git push to a bare repository myproject.git (usually on a remote server like github.com) so other developers can access my local changes.

时间: 2024-11-10 10:39:45

What is a bare git repository?的相关文章

把Git Repository建到U盘上去

Git很火.原因有三: 它是大神Linus Torvalds的作品,天然地具备神二代的气质和品质: 促进了生产力的发展,Git的分布式版本控制理念,并非首创,但非常适合开源社区的协作方式(不存在master-slave的关系) GitHub GitHub很好,号称代码界的facebook. facebook,twitter,Microsoft,vmware,redhat,LinkedIn,Yahoo等公司都在GitHub上有建立数目不等的repositories.一些知名开源项目,例如jQuer

把Git Repository建到U盘上去(转)

把Git Repository建到U盘上去 转 把Git Repository建到U盘上去 Git很火.原因有三: 它是大神Linus Torvalds的作品,天然地具备神二代的气质和品质: 促进了生产力的发展,Git的分布式版本控制理念,并非首创,但非常适合开源社区的协作方式(不存在master-slave的关系) GitHub GitHub很好,号称代码界的facebook. facebook,twitter,Microsoft,vmware,redhat,LinkedIn,Yahoo等公司

Git CMD - init: Create an empty Git repository or reinitialize an existing one

命令格式 git init [-q | --quiet] [--bare] [--template=<template_directory>] [--separate-git-dir <git dir>] [--shared[=<permissions>]] [directory] 命令参数 --quiet, -q 安静模式,只打印错误和警告信息. 实例 a) 创建版本库 [[email protected] git]$ mkdir hello_git [[email 

git推送报错: No path specified. See &#39;man git-pull&#39; for valid url syntax或does not appear to be a git repository以及remote: error: insufficient permission for adding an object to repository databa

本地(windows)代码想推送到linux自己搭建的git服务端,第一步是建立本地与服务端的关联,第二步是本地推送到服务端. 第一步需要看你本地工程是否从git上clone来的,如果是clone来的那就不存在第一步了.但如果是本地已经有了工程之后才想同步到git上,需要先到linux的git上新增同名git仓库并初始化.这里以ms-util工程为例: cd git mkdir ms-util.git cd ms-util.git git --bare init 接着修改用户属主和用户组属主,并

git: fatal: Not a git repository (or any of the parent directories): .git

在看书 FlaskWeb开发:基于Python的Web应用开发实战 时,下载完源码后 git clone https://github.com/miguelgrinberg/flasky.git 试着 切换到 提交历史 1a, $ git checkout 1a,出现error: fatal: Not a git repository (or any of the parent directories): .git 这个提示表明现在不在一个git repository目录下,需要切换到flask

解决:fatal: Not a git repository (or any of the parent directories): .git

fatal: Not a git repository (or any of the parent directories): .git 在用个git上传android项目时发现 git add file添加文件时出现这样错误: fatal: Not a git repository (or any of the parent directories): .git 提示说没有.git这样一个目录,解决办法如下: 接着在下一行直接输入git init就可以了!

新目录下使用git管理,未配置.git目录,报错fatal: Not a git repository (or any of the parent directories): .git

fatal: Not a git repository (or any of the parent directories): .git 第一次用Git,遇到这个错误提示,原来是这样的: fatal: Not a git repository (or any of the parent directories): .git This tells you that the directory you're in is not a git repository. Before you can add

git 解决fatal: Not a git repository

我用 git remote add origin [email protected]:michaelliao/learngit.git 添加远程库时提示: fatal: Not a git repository (or any of the parent directories): .git 提示说没有.git这样一个目录, 解决办法如下: 当时发现自己所在目录并非git初始化库目录,所以跳转到git库,重新运行ok;

getting “fatal: not a git repository: &#39;.&#39;” when using post-update hook to execute &#39;git pull&#39; on another repo

Here is the script that ultimately worked. I think the bit I was originally missing that prevented it from working remotely was the unset GIT_DIR #!/bin/shcd /path/to/working-copy/ || exitunset GIT_DIRgit pull repo branch exec git-update-server-info