
- Git - Home
- Git - Version Control
- Git - Basic Concepts
- Git - Command Line
- Git - Installation
- Git - First Time Setup
- Git - Basic Commands
- Git - Getting Help
- Git - Tools
- Git - Cheat Sheet
- Git - Terminology
- Git - Life Cycle
- Git - Get a Repository
- Git - Adding New Files
- Git - Recording Changes
- Git - Viewing Commit History
- Git Branching
- Git - Branches in a Nutshell
- Git - Creating a New Branch
- Git - Switching Branches
- Git - Branching and Merging
- Git - Merge Conflicts
- Git - Managing Branches
- Git - Branching Workflows
- Git - Remote Branches
- Git - Tracking Branches
- Git - Rebasing
- Git - Rebase vs. Merge
- Git - Squash Commits
- Git Operations
- Git - Clone Operation
- Git - Tagging Operation
- Git - Aliases Operation
- Git - Commit Operation
- Git - Stash Operation
- Git - Move Operation
- Git - Rename Operation
- Git - Push Operation
- Git - Pull Operation
- Git - Fork Operation
- Git - Patch Operation
- Git - Diff Operation
- Git - Status Operation
- Git - Log Operation
- Git - Head Operation
- Git - Origin Master
- Git Undoing
- Git - Undoing Changes
- Git - Checkout
- Git - Revert
- Git - Reset
- Git - Restore Operation
- Git - Rm
- Git - Switch Operation
- Git - Cherry-pick
- Git - Amend
- Git on the Server
- Git - Local Protocol
- Git - Smart HTTP Protocol
- Git - Dumb HTTP Protocol
- Git - The SSH Protocol
- Git - The Git Protocol
- Git - Getting Git on a Server
- Git - Setting up the Server
- Git - Daemon
- Git - GitWeb
- Git - GitLab
- Git - Third Party Hosted Options
- Distributed Git
- Git - Distributed Workflows
- Git - Contributing to a Project
- Git - Maintaining a Project
- Customizing Git
- Git - Configuration
- Git - Hooks
- Git - Attributes
- Git - Init
- Git - Commit
Git - Setting Up The Server
Setting up a server for Git repositories means configuring a server to host the Git repositories, which will allow the users to clone, pull, and push code.
A collaborative development environment is an ideal setup for setting the remote server. The common method of setting up a server is by using the SSH for secure access or a Git-specific server software.
The following steps can be performed to setup a Git server:
1. Preparation of the Server
In order to setup teh Git server, you need to have the access to a remote server, that in turn can host the Git repositiories. Just make sure your server is updated. Run the following commands:
-
Ubuntu / Debian:
sudo apt update && sudo apt upgrade
-
CentOS / Fedora:
sudo yum update
2. Installation of Git on the Server
Get the Git installed on your server to host the repositories.
-
Ubuntu / Debian:
sudo apt install git
-
CentOS / Fedora:
sudo yum install git
Check the version of git that is installed, in order to confirm. Run the following command:
git --version
3. Creation of a Git User
-
You should create a user to work with the Git repositiories, dedicately, over SSH. Run the following command to create the user:
sudo adduser git
-
Set a password for the Git user. Though it is optional, but recommended.
sudo passwd git
-
You need to grant the SSH access to this user. Copy the public SSH key from their local machine to the server. Each user needs to have their public key placed in the git users authorized_keys file.
su - git mkdir ~/.ssh chmod 700 ~/.ssh nano ~/.ssh/authorized_keys
Set the appropriate permissions:
chmod 600 ~/.ssh/authorized_keys
4. Creation of a Bare Repository
A bare repository is without a working repository. This bare repository acts like a central repository to which developers can push or pull from. Follow the steps for the same:
-
Switch to the Git User by running the following command:
su - git
-
Create a new directory for the project repository and choose a location where the repositories will be stored. Run the following command:
mkdir -p /srv/git/project.git
-
Initialize the bare repository, as it won't be having a working repository.
cd /srv/git/project.git git init --bare
5. Configuration of SSH Access
You need to configure SSH access in order to allow users to interact with the Git repository. You can clone the repository which will allow you to make changes, commit, and push these changes back to the server.
git clone git@your_server_ip:/srv/git/project.git
6. Setting the Permissions
If you need to allow multiple users to collaborate and work on the same repository, you need to set the permissions. By default, only the git user can push or pull the code. To allow other users you need to do either:
Among all the collaborators, share the git user.
All the users can be added to a specific group, having permission to read/write in the repository.
Run the following commands for group collaboration:
1. First create a group and add the users to it.
sudo groupadd gitgroup sudo usermod -aG gitgroup git sudo usermod -aG gitgroup otheruser
2. Change the permission for group.
sudo chown -R git:gitgroup /srv/git/project.git sudo chmod -R 770 /srv/git/project.git
7. Installation of Git Server Software (Optional)
You can install a Git server software such as GitLab, or GitHub, for a more robust user management with git services. There are few more optional steps that can be taken for a better Git server management.
Git hooks can be configured, which automates tasks, like running tests, sending notifications, etc.
Create cron jobs to backup your git repositories on a regular basis.
Manage the SSH keys so that users can be authenticated without needing to give the passwords.
Summary of Key Steps:
Install Git on the server.
Create a git user to manage the repositories.
Set up SSH access for users.
Create bare repositories for remote collaboration.
Optionally, install GitLab or GitHub for a full-featured Git management solution.