git init bare example |Video upload date:  · Duration: PT4M34S  · Language: EN

Learn how to create a bare Git repository as a central remote using git init --bare and a simple push workflow for sharing code.

If you want a no nonsense central repo that will not accidentally mess with anyone s working copy then a bare Git repository is your friend. It stores all the branches and history but does not have a working tree. That makes it perfect for a shared central repo that teams push to and clone from. Yes it sounds boring and stable on purpose.

What a bare repository actually is

A bare repository holds the Git database only. There is no checked out files to trip over. Use it when you want a central remote on a server or a local folder to act like a remote. This is standard version control hygiene if you like avoiding accidental overwrites and weird merge surprises.

Set up the bare repository

Make a dedicated folder that will live as the central store. Keeping it local is great for examples and for a quick central repo on a shared machine.

mkdir project.git
cd project.git
git init --bare

The command above initializes a repository without a working tree. That means no files to modify there, only Git objects and refs. Practical and safe.

Create a normal working repository

Now create a normal project where developers will edit files and commit. This is what you will push from.

git init myproject
cd myproject
echo "Hello README" > README.md
git add README.md
git commit -m "initial commit"

Link the working repo to the bare repo and push

Add the bare repo as a remote and push your branch. If your Git uses main replace master with main in the commands below.

git remote add origin ../project.git
git push origin master

Local path remotes are great for examples and for simple central repositories on a single server. For a real server you would use an SSH or HTTP remote instead but the workflow is the same.

Clone or fetch from the central repo

Other developers or automation can now clone that central store and get a normal working tree.

git clone ../project.git cloned
cd cloned
git status

Quick checklist

  • Use git init --bare to create a bare repository for sharing
  • Keep a normal working repository locally to make commits
  • Add the bare repo as a remote and push your branches
  • Clone the bare repo to get a working tree on other machines

Tips for grown up repos

  • Keep branch protections or server side hooks so people do not push broken code
  • Use hooks to enforce checks if you want automation to be mean but fair
  • Consider setting up SSH access and proper permissions for multi user servers

That is the whole ritual. You made a central repo that will not accidentally stomp a developer s working tree. It is simple and reliable and about as dramatic as a sensible filing cabinet. If you want more advanced server setups look into Git hosting like Gitea or GitLab but for many projects a bare repository is all you need to share code and keep sane version control.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.