Introduction

Setting up a private git server for your personal projects is quite easy to achieve. I use a private git server all the time - from a simple git setup as described in this article to a more complex setup in my homelab using gitea.

This post is related to the Secure SSH access with certificate based authentication and firewall rules article. As we will use certificate-based authentication to log in to the git server, I would recommend going through this article to set up the Linux server in a similar way.

To indicate where the commands are being executed, all sections are marked with Server or Client.

Installing git

Server

To install git, we have to log in as privileged user (sudoer) and execute

install git
[user@server]$ sudo yum install git-core

Then we switch to the new directory and initialize an empty git repository

initialize repository
[git@server]$ cd ~/repos
[git@server]$ git init --bare
Initialized empty Git repository in /home/git/repos/

Setup the client

Client

Now we can setup the git client. We first create a local directory which we will use for cloning the git repository.

local directory
[git@client]$ mkdir ~/git_repo

Now we can switch to the new directory and can clone the repository.

clone repository
[git@client]$ ~/git_repo
[git@client]$ git clone [email protected]:/home/git/repos

Create a new project

Client

We can now create a new project folder and create some initial content, e.g. a README.md file.

create README.md file
[git@client]$ mkdir ~/git_repo/repos/project1
[git@client]$ vi ~/git_repo/repos/project1/README.md
README.md
# Project 1

Project 1 description

Commit the changes

Client

Let's perform the first commit to push the changes to our git repository. We use git add to add files or directories to the staging area. git commit -m "Message to describe the change" is used to check in to our local repository on the client and git push to push the changes to the server.

commit changes
[git@client]$ git add project1/
[git@client]$ git commit -m "Initial Checkin"
[master (root-commit) 71823d9] Initial Checkin
 1 file changed, 3 insertions(+)
 create mode 100644 project1/README.md
[git@client]$ git push
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 4, done.
Writing objects: 100% (4/4), 286 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To [email protected]:/home/git/repos
 * [new branch]      master -> master

That's it, we have now a fully working git server, have created a repository and checked in our first project.