Git - Getting Git on a Server



The process to install Git on a server, generally involves several steps depending on your operating system (e.g., Linux, macOS, or Windows).

In order to set up a Git server, a new bare repository without a working directory must be created.

  • To achieve this, use the --bare option to clone an existing repository.

  • Usually bare repositories end with the suffix .git.

  • Use the following command to establish a basic repository called new_project.git.

git clone --bare new_project new_project.git

The new_project repository is cloned with this command, creating a new bare repository called new_project.git.

The Git directory data is kept in new_project.git once a bare repository has been created using git clone --bare.

This process is equivalent to moving the .git directory manually from new_project to new_project.git using the following method:

cp -Rf new_project/.git new_project.git

Isolating data from the Git repository without the working directory into new_project.git is still the main goal.

This configuration is common for server repositories where project files are not needed and only Git actions are needed.

Putting the Bare Repository on a Server

It is simple to set up a server and configure protocols after a bare repository new_project.git has been created.

If you wish to store Git repositories under /srv/git and have SSH access to example-server.com, you can use SCP to transfer the basic repository:

scp -r new_project.git [email protected]:/srv/git

The new_project.git bare repository is copied recursively (-r) to the /srv/git directory on the SSH-accessible server [email protected].

After storing our repository in /srv/git on the server, SSH-based read access users can clone it with the following commands:

git clone [email protected]:/srv/git/new_project.git

Users will also have automatic push access if they have write permissions to the server's /srv/git/new_project.git directory and SSH access.

When you use the --shared option to initialize a Git repository, Git will automatically assign write rights for the group.

Existing commits, references, and other repository data are unaffected by this action.

ssh [email protected]
cd /srv/git/new_project.git
git init --bare --shared

By creating a basic repository on a server with SSH access, setting up a Git repository for collaboration is simple.

  • SSH-capable server accounts are required, as well as read and write access to the repository for collaborators.

  • Small, private projects where participants can collaborate on the same project are appropriate for this approach.

  • Advanced setups, which will be covered later, include controlling of user accounts, granting public read access, and configuring web user interfaces for more thorough project management.

Small Setups

For teams that are new to Git or small setups, setting up a Git server can be simple.

It can be more difficult to manage user rights, particularly for read-only and read/write access to several repositories, while setting up a Git server.

Configuring Git Repositories with SSH Access:

  • It's easy to set up the initial repository there with minimal further setup if all developers have SSH access to the server already.

  • Use the filesystem permissions on the server's operating system for more intricate access control.

  • SSH access needs to be configured if repositories are to be located on a server without user accounts for every team member.

Options available are:

  • Setting up separate accounts for every team member, which is straightforward but may take some time.

  • Making a single git user account and adding users' SSH public keys to its `authorized_keys` file that require write access.

  • Ensuring that any authenticated user with shell access can use SSH by using SSH server authentication from an already-existing centralized source, such as LDAP.

Note: In order to learn about the steps to configure SSH Key, click here.

Summary

Following steps summarise the process of getting Git on server:

  • Installing Git − Using the package managers to install Git.

  • Configuring Git − Setting Up global Git configurations like username and email.

  • Setting Up Git Repositories − Creating bare repositories to act as remote repositories.

  • Setting Up Access Control − Configuring SSH key, permissions, or web-based Git management tools, so that the users can pull/push code from the server.

Advertisements