Git Tutorial

How to Setup Git on Server? Install & Git Setting Up Process

Benefits of Installing Git on Server

This is among the most important concepts in the complete Git tutorial for beginners. So far, we have learnt about: 

Now, let’s understand why would you want to set up your own Git server. Here are some of the primary benefits:

1. Enhanced safety

Although Git and other services have robust security features, accidents do happen, and they have in the past. Any sensitive data stored on third-party servers should be avoided wherever possible.

2. Increased control

You can adjust and improve the hosting environment for your specific needs if you manage your Git server. Many of the premium features that come included on your own server will cost you extra if you use a hosted service.

3. Extra options

There's no reason why you couldn't combine the two. It's fine if someone in your team wishes to host their part of the project on GitHub or another service. Git is a distributed version control system. Multiple remote repositories are possible.

How to Setup Git on Server?

Here is the step-by-step process on how to set up Git server:

Make a "git" user and a "git" group. Post a public SSH key to the "git" user, allowing you (or others) to log in as "git."

On the server, create a basic repository. Add a local Git project to the remote repository (the one you just created on the server). Changes to the git remote repository should be pushed.

- Choose location of the file

You must choose a file directory to save your remote Git repositories before you can build your first remote Git repository. You can save repositories to different file locations, but having them all in one directory is often easier.

- Create Git user account

First and foremost, you must create a "git" user account to which you will assign all of your git-related tasks. Remember, you have complete control over the title of this user account. The account's name, "git," is only a shorthand way of indicating what this user account was created for.

- Create Git user

Answer the questions as they are posed, or press Enter to jump forward to the next question. These questions are optional. Because you will not be utilizing passwords to log into this account, you can use anything for the password. Remember that password authentication is disabled by default on your server.

After you've created the Git user, use the su command to take over the role.

You must now create a .ssh directory for the git user in the "home" folder. To do so, you must first ensure that you are in the home directory by using the cd command.

- Create the .ssh directory

Copy mkdir .ssh.

Next, restrict access to the directory to the git user:

Copy chmod 700 .ssh.

A .ssh directory now contains your "authorised keys" file, which is used to verify login requests. 

Copy touch .ssh/authorized keys.

Similarly, change the privileges to make the file exclusively available to the git user:

Copy chmod 600 .ssh/authorized keys.

You now have the appropriate directory and file to set up SSH logins.

But, before we go any further, double-check that the "git" group is permitted to authenticate in this manner.

You can accomplish this by modifying your SSH configuration file and adding "git" to the list of allowed groups.

Using Git Server on Windows

To run Git on windows, here’s what you need to do- 

  1. Download the latest Git for Windows installer.

  2. After successfully starting the software, you need to see the Git Setup wizard screen. Follow the Next and Finish prompts to complete the installation. For the most part, the default settings are sufficient.

  3. Start a Command Prompt (or Git Bash if during installation you elected not to use Git from the Windows Command Prompt)

  4. Replace Emma's name with your own in the following commands to configure your Git login and email. 

  5. Install the Git credential helper on Windows if you want to be extra safe.

  6. Bitbucket allows you to push and pull files to and from remote Git repositories through HTTP. You must provide a username/password combination every time you interact with the remote repository. The Git Credential Manager for Windows allows you to save these credentials instead of having to type them in every time.

Best Web Hosting for Git Projects

When it comes to software development, Git is one of the most popular version control and code management systems out there. It is an open-source engine that lets you track any changes made to your code, whether in the form of files or whole folders. Your code can be hosted on the cloud or locally on your hard drive.

GitHub and other similar services are very valuable for software developers because they allow them to collaborate more effectively. This is done thanks to a plethora of features offered by the hosting service, such as issue tracking and task management tools. 

You can also let others see what you're working on or read your documentation by making it public on these platforms. This way, others don't have to download and install Git on their own devices just to see what you've been working on.

Here are some of the prominent hosting options:

  • Bitbucket

  • GitHub    

  • GitLab

  • Perforce

  • Beanstalk

  • Amazon AWS CodeCommit

  • Codebase

  • Microsoft Azure DevOps

  • SourceForge

  • Gerrit

Important Concepts You Must Know

1. Public SSH Key

An SSH key is a set of cryptographic keys that is used to verify a user's or process's identity when using the SSH protocol to connect to a distant system.

The SSH protocol provides secure encrypted communications between two networked computers and is often used to administer and configure systems remotely, especially in server environments.

Each end of an SSH connection has an encryption key pair consisting of a public key and a private key, which are mathematically related so that messages encrypted with one can only be decrypted with the other.

Using a public key for authentication makes sharing code between multiple users easier because you do not need to store your private keys on a central server. It works well for teams of developers working together on a code repository, or if you want to allow users to log in to your system without storing passwords or creating other accounts.

2. Smart HTTP 

HTTP smart is a protocol that lets you access Git repositories over HTTPS, and it's arguably the most popular way to use Git presently. Instead of needing to create separate URLs for anonymous and authenticated access, you can simply use the same one.

HTTP smart works by using a proxy server to handle authentication and encryption. The proxy server sets up a tunnel to your Git repository and then serves over HTTPS. 

If you're accessing an anonymous repository, then your browser can connect directly to the proxy as if it were a web page, and if you're accessing an authenticated repository, then your browser makes an HTTP Basic Auth request to the proxy before being served through the tunnel.

This makes it possible to send requests through the tunnel even if they don't look like HTTP requests—for example, asking for a specific revision of a file (via either sync or the Git protocol) or running a Git clone via the URL. It also means that any HTTP request made through the tunnel will be properly secured by HTTPS encryption.

The Git community has embraced HTTP smart because it lets them use one URL for both anonymous and authenticated access without having to set up separate URLs for each type of access. 

Did you find this article helpful?