What is git init command- git init bare?
Git init command creates a new git repository. It is an initial command from the list of git commands. This tutorial includes, how to create a git repository in git using Linux. Examples in this tutorial are based on CentOs and assume that git is already installed on the machine.
Type of git repository?
Now you have decided to create a repository for you and your team? What options should you use in git init command or git init is all you need only?
git init command creates a repository with actual files. The directory created is the working directory. That includes a full working tree. The directory, have .git directory folder for all revision history. All files present in the working directory are as checkout copies of all files. This is suitable for you if you are the only user of the repository. I guess here not as you have a team. Want git repository to be accessible to all developers.
Another type of repository is a bare repository. A bare git repository is created by using –bare option in git init command. A bare repository can be shared among multiple developers over the network. Developers need to know the URL and login credentials for the repository.
You want to avail repository to all developers in your team, so creating a bare repository is good for you and team.
Git repository server location:
From where the git repository will be accessed? From inside office premises (over LAN)? Or from anywhere? If from anywhere, then the repository hosting server should have public IP or you can also choose existing platforms GitHub, bitbucket, etc.
If due to limitation or any other factor, if the requirement is, give access from office premises/LAN only. Then a machine on LAN (Local Area Network, have an internal IP address ) is a suitable option.
In this tutorial, the git repository will be created on a Linux machine in LAN. The IP address of the machine which will host the git repository is 192.168.1.159. The git user is the root user of the Linux machine. You can create a new user for accessing the git repository. For simplicity, the user is a root user in this example.
Create git bare repository:
After ssh on machine 192.168.1.159
The Above will create a bare repository, now assign the bare repository a working tree.
- Do SSH on another machine (192.168.1.160) in the same LAN.
- Will create a local repository (git init command),
- Add a new file (git add command) and commit the new file (git commit).
- Push the code changes to the central repository.
The remote repository is ready with the working tree. Other users will clone from machine 192.168.1.159 to machine 192.168.1.155, in the same LAN. Ssh to a machine. The git clone command is in git, so clone a git repository on a local machine.
Great:), git repository is ready. Invite developers to work on this.