How to set up a private Git server
Start committing code to your private Git server in just 4 steps.
Setting up a private Git repository server is easy.
Follow these four steps and you can start committing code to your private Git Server from any number of
You can use a virtual machine or a bare-metal server for the
Do step one to three on the
Git Server and the fourth on the
#1 Install Git server
We are using Ubuntu in the
Git Server so will use
apt for installing Git. If you are using a different Linux distribution, use the appropriate package manager.
Install Git in the
sudo apt update sudo apt-get install git-core
#2 Create git user
git user in the
sudo adduser git
Type in a password when prompted.
This will create the
git user and home directory
/home/git for the user.
#3 Create the repository on the server
Do NOT switch to the
git user yet. We'll do it shortly afterwords.
Create a directory for storing git repos on the server and give permission to
sudo mkdir /srv/git sudo chown git /srv/git/ sudo chgrp git /srv/git
git user and create a repository.
su git cd /srv/git mkdir coffee-app.git cd coffee-app.git git init --bare
We are using
coffee-app.git as our repository name. You can use any name you like.
#4 Start commiting from the development machine
Do this on the
We assume that Git client is already installed in the workstation.
Configure the global email and username for Git, if you haven't done it yet.
git config --global user.email "email@example.com" git config --global user.name "cloudqubes"
coffee-app (use your preferred name.)
mikdir coffee-app cd coffee-app echo "coffee" > README.md git init git add . git commit -m "initial commit" git remote add origin firstname.lastname@example.org:/srv/git/coffee-app.git git push -u origin master
Note that we are using the IP address of the
Git Server. Use the correct IP address in your case.
You will be asked to enter the password of the
And, that's it.
You have successfully made the first code commit to your private Git Server.
If you think it's too much work to enter the password everytime you are push, proceed to the next step.
Configure SSH keys (optional)
Do this in the
Developer Workstation to free yourself you from having to type in the password every time you push code to the server.
Create new SSH keys.
ssh-keygen -f ~/.ssh/git_server ssh-copy-id -i ~/.ssh/git_server email@example.com
Add the following lines to
Host git_server User git Hostname 10.212.251.186 IdentityFile ~/.ssh/git_server
Make sure to use the correct IP address.
Update the remote URL in the Git repository.
git remote set-url origin git_server:/srv/git/coffee-app.git
Take note of the
git_server in the URL. It's the value we used for the
Host parameter in the
Now, you can continue committing without having to enter the password.