How to set up a Git repository in minutes on Linux

7 months ago 148
PR Distribution

If you request a speedy codification repository, you person everything you request with git and SSH. Jack Wallen shows you however it's done.

Developer young woman

Image: Getty Images/iStockphoto

Sometimes you conscionable request to deploy a speedy Git repository truthful you tin collaborate connected a project, backmost up your codification oregon location your files connected a distant machine. When you consciousness similar doing that, you don't privation to person to walk an hr oregon truthful deploying a server and mounting it up … particularly erstwhile you already person everything you request astatine your fingertips.

I'm going to amusement you however you tin rapidly deploy a Git repository utilizing conscionable git and ssh. You should beryllium capable to rotation this up successful little than 5 minutes (two, if you benignant fast).

Let's get busy.

What you'll request

The lone happening you request is simply a Linux instrumentality (either a desktop oregon a server) to big the repository and a idiosyncratic with sudo privileges. That's it.

SEE: Hiring Kit: JavaScript Developer (TechRepublic Premium)

How to instal git

You astir apt already person git installed connected your section machine. On the disconnected accidental you don't person it installed connected the distant machine, log into it and instal with:

  • For Debian-based systems - sudo apt instal git -y
  • For Red Hat-based systems - sudo dnf instal git -y

Git should present beryllium installed.

Stay logged into the distant machine.

How to make a git idiosyncratic and transcript your SSH keys

On the distant instrumentality make a git idiosyncratic with:

sudo adduser git

Give the caller idiosyncratic a password and reply the remaining questions.

Change to the git idiosyncratic with:

su git

Change into the git users' HOME directory with:


Create the .ssh directory and springiness it the due permissions:

mkdir .ssh chmod 700 .ssh

Create the authorized_keys record and springiness it the close permissions with:

touch .ssh/authorized_keys chmod 600 .ssh/authorized_keys

Now, connected your section instrumentality presumption the record of the idiosyncratic who volition beryllium moving connected the git repository with the command:

cat /home/USER/.ssh/

Where USER is the idiosyncratic who'll beryllium moving with git. Copy that cardinal to your clipboard. 

Open the authorized_keys record connected the distant instrumentality with:

nano /home/git/.ssh/authorized_keys

Paste the cardinal and past prevention and adjacent the file.

How to make the repository

Back connected your distant instrumentality make a repository directory (still arsenic the idiosyncratic git) successful the git users' location with:

mkdir /home/git/git_repo

Change into that directory with:

cd /home/git/git_repo

Create a caller task directory (we'll sanction it PROJECTX) with:


Change into that caller directory with:


Initialize the caller (bare) git repository:

git --init bare

How to clone the caller repository

Back astatine your section machine, contented the command:

git clone git@REMOTE:/home/git/git_repo/PROJECTX

Where REMOTE is the IP code of the distant instrumentality lodging the git project.

You should beryllium prompted for your SSH cardinal authentication password. Upon palmy authentication, the task volition clone and you're acceptable to go. If you privation to trial this repository, make a README successful PROJECTX (on the section machine) with:


Now, we'll propulsion the changes to the repository by adding the files, creating a commit, and pushing with:

git adhd --all git perpetrate -m "Added README file" git propulsion root master

There ya go. You've created a repository connected a distant machine, initialized a caller project, cloned the task to a section machine, made changes, and pushed your changes to the repository. This should instrumentality you little than 5 minutes.


Developer Essentials Newsletter

From the hottest programming languages to the jobs with the highest salaries, get the developer quality and tips you request to know. Weekly

Sign up today

Also spot

Read Entire Article