How to Upload a Local Bare Git Repository to GitHub and Make It Public

0saves

🚀 How to Upload a Local Bare Git Repository to GitHub and Make It Public

Sometimes, during your development workflow, you might have a bare Git repository stored locally — for example, as a central repository for multiple team members or part of a custom deployment process. But eventually, you might want to push this repository to GitHub, make it public, and possibly open it to contributions or make it easier to browse history online.

In this post, we’ll walk step-by-step through how to upload a local bare Git repository to GitHub, including pushing all branches and tags.


🧠 What Is a Bare Git Repository?

A bare Git repository is a repository without a working directory. It only contains the .git folder contents — that is, the Git object database, references, and configuration. You usually don’t work directly inside a bare repo (no editing files or running builds), but it’s often used for remote storage or central version control.

You can recognize it by its structure and the lack of a working tree. Its remote might look like this:

$ git remote -v
origin  file:///home/username/your-website.git (fetch)
origin  file:///home/username/your-website.git (push)

🛠️ Step-by-Step Guide

1. Create a New Repository on GitHub

Head over to https://github.com/new and:

  • Set the repository name (e.g. your-website)
  • Choose Public
  • Do not initialize with a README, .gitignore, or license — we’ll be pushing our own history

Click Create repository to get your new GitHub repo.


2. Add GitHub as a Remote in Your Bare Repo

Navigate to the folder containing your bare repo:

cd /home/username/your-website.git

Now add the GitHub URL as a new remote (call it github):

git remote add github https://github.com/your-username/your-website.git

🔐 If you’re using SSH instead of HTTPS, you can use:

git remote add github git@github.com:your-username/your-website.git

3. Push Everything to GitHub

The safest and most complete way to upload your entire repository — including all branches, tags, and history — is using the --mirror option:

git push --mirror github

This command is similar to --all, but it also includes references like tags and remote-tracking branches.


4. Verify on GitHub

Go back to your repository page on GitHub, and you should see:

  • All your commits
  • All your branches
  • Any tags you may have created

Congrats! 🎉 Your local bare repository is now on GitHub and public!


🧩 Bonus Tips

Add a README

You might want to add a README.md to introduce the purpose of the project. You can clone the repo into a working directory and commit the README from there.

git clone https://github.com/your-username/your-website.git
cd your-website
echo "# Your Website" > README.md
git add README.md
git commit -m "Add README"
git push origin main

Add a .gitignore

Add a .gitignore to clean up the repo and avoid committing unnecessary files. You can use GitHub’s gitignore templates as a base.

Setup GitHub Actions (CI/CD)

Once your project is public, GitHub Actions is a powerful tool for automated testing, deployment, or code checks. You can add a .github/workflows directory with workflow YAML files for different CI tasks.


🎯 Conclusion

Uploading a local bare Git repository to GitHub is a straightforward but powerful step — whether you’re archiving, collaborating, or going open-source. By using --mirror, you preserve every aspect of your local Git history.

Have questions about CI/CD, GitHub Pages, Laravel deployment, or PHP best practices? Feel free to connect or drop a comment!


Would you like a Markdown version for posting to your blog, Reddit, or GitHub?

Leave a Reply

Your email address will not be published. Required fields are marked *