How to clone your private repository from GitHub to server, Droplet, VDS, etc?
Tags: productivity, tutorial, git, deploy
Published: 2020-01-06 17:15:36

## Introduction

Welcome back! The “**(Quick) How to**” series continue. 

Today, we solve huge misunderstood thing: clone **private** repository from GitHub on your server. Don’t switch the channel 😃

## Objectives of the article

1. Show one of the **easiest** ways to clone private GitHub repository.
2. Train your console skills.

## Prepare setup

First, connect to your server (Droplet, VDS, etc) and generate SSH key:

```console
$ sudo ssh-keygen
```

> If you want, choose path and name for your key. I always use default path (`~/.ssh`) and name, like **project_name_rsa**.

Next step, create SSH config:

```console
$ sudo cat >~/.ssh/config <<EOL

Host project_name
Hostname github.com
User git
IdentityFile ~/.ssh/project_name_rsa

EOL
```

> Don't forget to change my `project_name` to yours!

OK! Copy public key to clipboard and go to your GitHub repository settings:

```console
$ sudo cat ~/.ssh/project_name_rsa_key.pub
```

Add copied public key to **Deploy Keys** section:

![github allow write access](https://thepracticaldev.s3.amazonaws.com/i/98xqvo0sqn01yj1wuu8w.png)

> Don’t forget to check **Allow write access**. 

That’s it. 🎉

![let's clone private git repo](https://thepracticaldev.s3.amazonaws.com/i/yqgrxip2kg0te55bzw94.jpg)

## Let’s clone it!

You may `git clone` your **private** repository to server by command:

```console
$ sudo git clone project_name:<user>/<repo>.git
```

## How to update?

For update, type into your project directory:

```console
$ git pull
```

## What’s next?

Get automation of routine tasks on a new server (Droplet, VDS, etc) with **Virtual Server Auto Config** (or VSAC for short). Just `git clone` and run it! 👇

{% github koddr/vsac %}

## Photos by

[Title] Nicole Wolf https://unsplash.com/photos/CZ9AjMGKIFI
[1] Azharul Islam https://unsplash.com/photos/9LMGWHqUwnc

## P.S.

Questions for self-study practice:

- Which console command may generate SSH key?
- What’s happen when your run `cat ./file.txt` command at console?
- Why a `sudo` command prefix are important?

If you want more articles (like this) on this blog, then post a comment below and subscribe to me. Thanks! 😻

And of course, you can help me make developers' lives even better! Just connect to one of my projects as a contributor. It's easy!

My projects that need your help (and stars) 👇

- 🔥 [gowebly][gowebly_url]: A next-generation CLI tool for easily build amazing web applications with Go on the backend, using htmx & hyperscript and the most popular atomic/utility-first CSS frameworks on the frontend.
- ✨ [create-go-app][cgapp_url]: Create a new production-ready project with Go backend, frontend and deploy automation by running one CLI command.
- 🏃 [yatr][yatr_url]: Yet Another Task Runner allows you to organize and automate your routine operations that you normally do in Makefile (or else) for each project.
- 📚 [gosl][gosl_url]: The Go Snippet Library provides snippets collection for working with routine operations in your Go programs with a super user-friendly API and the most efficient performance.
- 🏄‍♂️ [csv2api][csv2api_url]: The parser reads the CSV file with the raw data, filters the records, identifies fields to be changed, and sends a request to update the data to the specified endpoint of your REST API.
- 🚴 [json2csv][json2csv_url]: The parser can read given folder with JSON files, filtering and qualifying input data with intent & stop words dictionaries and save results to CSV files by given chunk size.

<!-- Footer links -->

[gowebly_url]: https://github.com/gowebly
[cgapp_url]: https://github.com/create-go-app
[yatr_url]: https://github.com/koddr/yatr
[gosl_url]: https://github.com/koddr/gosl
[csv2api_url]: https://github.com/koddr/csv2api
[json2csv_url]: https://github.com/koddr/json2csv