So far, you have learned how to operate and manage your work in your own environment. You know how to initiate Git repositories and what processes lie behind saving Git files. However, if you plan to work in a team of several developers, you must have a remote directory for your collaboration. That is where you need to learn how to set up a Git server.
Setting up Git server is relatively easy - you only need to know a particular command which you will have to run. Your remote repository will be a collaboration point for the developers who work on the same project. It is convenient as you will be able to access it even if your device is offline. That adds more reliability to work.
In this tutorial, you will learn not only how to set up Git server, but also how to obtain public SSH keys for every user. This is a common method among various systems to authenticate the users and provide or deny access to remote places. Getting SSH keys is essential so that each of them could access the remote repository after setting up Git server.
All the necessary information is below, so let's dive in!
Setting up Git Server: Main Tips
- For your own work you can use local repositories.
- For collaboration you will need a remote repository where all the common work will be saved.
- In order to have a remote repository, you will need to set up Git server and obtain SSH public key.
Initiating .Git Repository
Technically, it is possible to save your collaborative work in one of the private repositories; however, it is severely recommended not doing so. It is easy to confuse the repositories and accidentally destroy the work that has been done. Therefore, it is a common practice to run a Git server for a remote repository.
This particular repository is bare as it doesn't have any working directory in it - it simply is a collaboration point for your team. Such repositories have the extension .git. To initialize such a repository, you have to run the following commands:
$ mkdir my_repo.git
$ cd my_repo.git
$ git --bare init
You can check the status of the process by the command $ ls. If you successfully created a repository, the received response should be as the following, only with your location information:
Initialized empty Git repository in /home/gituser-m/my_repo.git/
- Easy to use with a learn-by-doing approach
- Offers quality content
- Gamified in-browser coding experience
- The price matches the quality
- Suitable for learners ranging from beginner to advanced
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid Certificates of completion
Git Server Configuration and SSH Keys
In order to have your remote repository placed somewhere accessible remotely, you must run a Git server. The Git server setup is not hard at all - you need to do some configuration, and each user of the Git server must obtain public SSH keys.
Before you begin to setup Git server, it might be a good idea to check if you have a key in general. The keys are usually placed in the ~/.ssh directory. To check it, you should run the following command:
$ cd ~/.ssh
authorized_keys2 id_dsa known_hosts
If you have a file with .pub ending, this is your public key. The file above is a private key; usually, they are named id_rsa or id_dsa.
If you do not have a key, you will see a message that no such directory exists. If this is the case, then each user of the system have to generate it. To be able to obtain the keys, run this command:
If executed successfully, you will be informed that a pair of rsa keys are being generated. One of them is public and the second one is private. After that you will be told where the keys have been placed and their fingerprint information.
Each user has to generate their own key in order to be authenticated by the Git server. They should send their public key to you or the person who is in charge of setup Git server and its administration. To do that is easy: they have to copy the contents of the .pub file and send this information to the administrator.
Setting up Git Server: Summary
- Local repositories are the most convenient for your own work.
- It is a common practice to have a remote repository for the collaborative work.
- Git server setup is the primary step for a remote repository, each user of it also must get SSH public keys.