Bootstrap FreeKB - Git (Version Control) - Create a repository using the git init command
Git (Version Control) - Create a repository using the git init command

Updated:   |  Git (Version Control) articles

The git init command can be used to create a new repository. This is typically done after installing Git to create a new repository on the Git server. The repository on the Git server is known as the origin repository.

]$ sudo git init /usr/local/example.git
Initialized empty Git repository in /usr/local/example.git/.git/

 

The --bare option is used to create a shared repository that does not contain a working directory, which means you would not be able to add and commit files to the origin repository directly. Instead, you would have to clone the origin repository and then used the git pull and git push commands to download and upload files from the origin repository. With --bare, you will first want to use the groupadd command to create a group that will be used by git.

groupadd my-group

 

Then create the directory for the new repository.

mkdir /usr/local/example.git

 

And set the group add the owner of the directory.

chgrp my-group /usr/local/example.git

 

And then create the empty, shared repository using --bare and --shared=all used. 

~]# git init --bare --shared=all /usr/local/example.git
Initialized empty Git repository in /usr/local/example.git/

 

And then use the git config command to set the global shared repository flag to true.

git config --global core.sharedRepository "true"

 

This is good, because the idea here is that users that want to use the origin Git repository would use the git clone command to clone the origin Git repository (such as example.git) to a directory on their PC (such as /home/john.doe/git), make a change to a file in the cloned repository on their PC (such as example.txt), use the git commit command to commit the change to the file, and to then use the git push command to upload the file to the origin Git repository.

 

By default, the new repository should contain the following files and directories.

]$ ls -l /usr/local/example.git
drwxr-xr-x. 2 root root    6 Aug 14 05:35 branches
-rw-r--r--. 1 root root   66 Aug 14 05:35 config
-rw-r--r--. 1 root root   73 Aug 14 05:35 description
-rw-r--r--. 1 root root   23 Aug 14 05:35 HEAD
drwxr-xr-x. 2 root root 4096 Aug 14 05:35 hooks
drwxr-xr-x. 2 root root   20 Aug 14 05:35 info
drwxr-xr-x. 4 root root   28 Aug 14 05:35 objects
drwxr-xr-x. 4 root root   29 Aug 14 05:35 refs

 

 Clone a repository using the git clone command




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 602f76 in the box below so that we can be sure you are a human.