What is git init command ?
Git init command creates a new git repository. It is initial command from the list of git commands. This tutorial includes , how to create git repository on linux. Example in this tutorial are based on CentOs and 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. Directory includes a full working tree. The directory , have .git directory folder for all revision history. All files present in working directory are as checkout copies of all files. This is suitable for you , if you are the only user of repository.I guess here not as you have team. Want git repository to be accessible to all developers.
Other type of repository is bare repository. Bare git repository is created by using --bare option in git init command. 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 developer in your team, so creating a bare repository is good for you.
Git repository server location:
From where the git repository will accessed? From inside office premises (over LAN)? Or from any where ? If from any where, then the repository hosting sever should have public ip or you can also choose existing platforms github ,bitbucket etc.
If due to limitation or any other factor , if requirement is , give access from office premises/LAN only . Then a machine on LAN (Local Area Network, have internal ip address ) is suitable option.
In this tutorial the git repository will be created on a linux machine in LAN. The ip address of machine which will host the git repository is 192.168.1.159 . The git user is the root user of linux machine. You can create a new user/users for accessing git repository. For simplicity user is root 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 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 central repository.
The remote repository is ready with working tree. Other user will clone from machine 192.168.1.159 to the machine 192.168.1.155, in same LAN. Ssh to machine. The git clone command is in git , so clone a git repository on local machine.
Great 🙂 , git repository is ready. Invite developers to work on this.