Create a Master branch in the Bare Git repository
You can only push and pull from an empty git repository. You may encounter errors when you try to check out a ref in a bare git repository.
This article will discuss creating a master branch in an empty git repository.
Create a master branch in the bare Git repository
As we mentioned before, you can't do a lot in an empty git repository. Let's try to check out the master branch in a bare git repository.
We will create an empty directory called Test-Repo.git and initialize a bare repository.
Order:
$ git init --bare
Output:
We cannot develop in a bare git repository. To create a master branch, we have to create a test clone repository and clone it there.
We will create a test clone folder and initialize a git repository.
Order:
$ git init
Output:
Next, we clone our bare repository into our test clone repository.
Order:
$ git clone C:/Test-Repo.git
Output:
Then create a README.md file and commit it to our test clone repository.
Order:
$ touch README.md
Next, we'll add the files to commit.
Order:
$ git add README.md
$ git commit -m "Initial Commit"
Output:
All that's left is to push our master branch and changes to the bare git repository.
Order:
$ git push C:/Test-Repo.git master
We treat our bare repository as if it were a hosted server, but we use the path to the bare repository instead git push origin master
.
The above command should create a master branch in our bare repository using our "initial commit".
Output:
Let's check if we have the master branch and its commits in our bare repository.
Order:
$ git branch
$ git log
Output:
Summarize
We can't do development in a bare repository. The best option is to clone it into another git repository and push a branch from there.
When cloning, be sure to enter the correct bare repository path.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Switch remote Git branch
Publish Date:2025/04/04 Views:182 Category:Git
-
This article will show you how to switch remote Git branches using checkout the command. The version control tool that allows you to support and manage variable versions of your application in a team of members is the Git version control to
Switch to a tag in Git
Publish Date:2025/04/04 Views:127 Category:Git
-
Git is one of the top version control systems used by teams around the world. Like other version control systems, Git also allows you to mark certain points in your repository's history as important. Typically, developers use this to mark r
Switching between branches in Git
Publish Date:2025/04/04 Views:64 Category:Git
-
In this article, we will learn how to switch branches in Git. Git is a distributed version control system and is an excellent tool for version control in a collaborative development environment. In Git, we create repositories, and in reposi
Undoing a checkout in Git
Publish Date:2025/04/04 Views:155 Category:Git
-
The command git checkout is used to update the repository to a specific point in the project's history. When we pass it a branch name, it switches to the branch we want to be currently at. This command is also used to undo git add the comma
Undo local changes to a single file in Git
Publish Date:2025/04/04 Views:159 Category:Git
-
In this article, we'll discuss how to roll back files to our preferred versions using commands like git checkout and git reset . Although Git makes it easy to reset files and repositories, the concept of undoing changes in Git is a little m
Difference between Git Switch and Checkout
Publish Date:2025/04/04 Views:182 Category:Git
-
Git is recognized as a unique open source platform that enables users to work with its convenient and simplest command line and a large number of commands. It increases its command line by introducing new versions every day. With the new ve
Reattaching HEAD in Git
Publish Date:2025/04/04 Views:72 Category:Git
-
A Git repository can be defined as a set of objects and references. Branches are the objects we use to represent our work. Git also handles tags that refer to commits in a specific branch. commit Probably the state of the source code at a p
Head in Git
Publish Date:2025/04/04 Views:166 Category:Git
-
Most of the time, in our Git documentation, head refers to the top of a Git repository, called the repository's head . But the question is what exactly is head HEAD in Git ? HEAD In this article, we will learn about that Git HEAD , but befo
Stop tracking a remote branch in Git
Publish Date:2025/04/04 Views:123 Category:Git
-
This article explains how we can stop tracking a remote branch in Git. By now, you must be very familiar with the concept of tracking remote branches. This session will cover the various methods you can use to stop tracking a remote branch.