创建自己的github

by Shashank Sharma

通过Shashank Sharma

创建自己的GitHub(kinda) (Create your own GitHub (kinda))

In order to do any collaboration in Git, you’ll need to have a remote Git repository. Let’s cover step by step how you can create a Git server on an AWS EC2 instance.

为了在Git中进行任何协作,您需要具有一个远程Git存储库。 让我们逐步介绍如何在AWS EC2实例上创建Git服务器。

First, let’s cover some of the basics.

首先,让我们介绍一些基础知识。

裸vs非裸仓库 (Bare vs Non-bare repository)

A git repository that has no working directory is called a “bare” repository. A “barerepository in Git just contains the version control information and no working files (no tree). It doesn’t contain the special .git sub-directory. Instead, it contains all the contents of the .git sub-directory directly in the main directory itself.

没有工作目录的git存储库称为“裸”存储库。 Git中的“ 裸露存储库仅包含版本控制信息,没有任何工作文件(没有树)。 它不包含特殊的.git子目录。 相反,它直接在主目录中包含.git子目录的所有内容。

Create: git init --bare
Clone: git clone --bare $URL

Non-bare repository has a checked-out working tree with .git sub-directory.

非裸仓库有一个带有.git子目录的检出工作树。

Create: git init
Clone: git clone $URL

You should use a non-bare repository to work locally and a bare repository as a central server/hub to share your changes with other people. For example, when you create a repository on github.com, it is created as a bare repository.

您应该使用非裸存储库在本地工作,并使用裸存储库作为中央服务器/集线器,以与他人共享您的更改。 例如,当您在github.com上创建存储库时,它被创建为裸存储库。

Bare repositories are smaller than non-bare repositories. As bare repository do not have working copy, any changes pushed to them won’t cause conflicts. Bare repository by convention uses names with the .git postfix.

裸存储库小于非裸存储库。 由于裸存储库没有工作副本,因此推送到它们的任何更改都不会引起冲突。 裸仓库按惯例使用带有.git后缀的名称。

协议 (The Protocols)

Git can use four major protocols to transfer data: Local, HTTP, Secure Shell (SSH) and Git.

Git可以使用四种主要协议来传输数据:本地,HTTP,安全Shell(SSH)和Git。

1. Local Protocol: the most basic protocol, where the remote repository can reside on any shared mounted disk. You can clone a local repository like this:

1. 本地协议:最基本的协议,远程存储库可以驻留在任何共享的已安装磁盘上。 您可以像这样克隆本地存储库:

git clone /var/local/repository

2. HTTP protocol: This runs over standard HTTP/S ports. It can use things like username/password basic authentication rather than having to set up SSH keys. If you use this, you can use the same URL to view or clone the repository, like with Github.

2. HTTP协议:它运行在标准HTTP / S端口上。 它可以使用用户名/密码基本身份验证之类的东西,而不必设置SSH密钥。 如果使用此功能,则可以使用相同的URL来查看或克隆存储库,例如使用Github。

3. SSH protocol: This is the most common transport protocol for Git when self-hosting. This is because SSH access to servers is already set up in most places — and if it isn’t, it’s relatively straight-forward to do.

3. SSH协议:这是自托管时Git最常见的传输协议。 这是因为在大多数地方已经建立了对服务器的SSH访问,如果没有,则相对简单。

4. Git protocol: The Git protocol is often the fastest network transfer protocol available. This is a special daemon that comes packaged with Git. It listens on a dedicated port (9418) that provides a service similar to the SSH protocol, but with absolutely no authentication.

4. Git协议: Git协议通常是可用的最快的网络传输协议。 这是Git随附的特殊守护程序。 它在专用端口(9418)上侦听,该端口提供类似于SSH协议的服务,但绝对没有身份验证。

In depth explanation of these protocols is beyond the scope of this article. For more details, you can check https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols.

这些协议的深入解释不在本文讨论范围之内。 有关更多详细信息,您可以检查https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols 。

在EC2实例上设置Git服务器 (Setting up Git server on an EC2 instance)

Now lets start get started with the reason you’re here — to set up a Git server. If you haven’t already set up an EC2 instance with SSH access, follow this guide to create one.

现在,从这里的原因开始吧-设置一个Git服务器。 如果您尚未设置具有SSH访问权限的EC2实例,请按照本指南进行操作。

I am using an Ubuntu t2.micro instance for this exercise.

我正在为此练习使用Ubuntu t2.micro实例。

a) Login to your EC2 instance using SSH.

a)使用SSH登录到您的EC2实例。

-> ssh -i ~/.certs/cert.pem ubuntu@54.254.174.183

b) Install Git.

b)安装Git。

-> sudo apt-get install git

c) Create a bare repository which will be your remote Git repository.

c)创建一个裸仓库,它将成为您的远程Git仓库。

-> mkdir gitserverexcersise.git-> cd gitserverexcersise.git-> git init --bare

This will create your bare empty repository. At this point of time you already have a Git repository ready to be cloned. But to clone this from your local system, you need to add your pem file to your ssh config.

这将创建您的空仓库。 此时,您已经准备好克隆Git存储库。 但是要从本地系统克隆此文件,您需要将pem文件添加到ssh配置中。

d) Open another terminal and add this instance to SSH config. You can find SSH config file in home directory .ssh folder. If you don’t have this folder you can create one. And edit or create config file in preferable text editor.

d)打开另一个终端,然后将此实例添加到SSH配置中。 您可以在主目录.ssh文件夹中找到SSH配置文件。 如果没有此文件夹,则可以创建一个。 并在首选的文本编辑器中编辑或创建配置文件。

-> vi .ssh/config

Add entry for your instance like

为您的实例添加条目,例如

Host gitserver HostName 54.254.174.183 User ubuntu IdentityFile ~/.certs/cert.pem

And save.

并保存。

e) Close this terminal and open new terminal. Now you should be able to login to ec2 instance using

e)关闭此终端并打开新终端。 现在您应该能够使用以下命令登录ec2实例

-> ssh gitserver

If you able to login then you can clone your repository to your local system using:

如果可以登录,则可以使用以下方法将存储库克隆到本地系统:

-> git clone gitserver:gitserverexcersise.git

Congratulations! You have successfully setup a remote Git server and now can push and pull to that server.

恭喜你! 您已经成功设置了远程Git服务器,现在可以将其推入并拉到该服务器。

设置GitWeb (Setting up GitWeb)

Now that you have basic read/write and read-only access to your project, you may want to set up a simple web-based visualizer. Git comes with a CGI script called GitWeb that is sometimes used for this. Follow below steps to setup GitWeb.

现在,您对项目具有基本的读/写和只读访问权限,您可能想设置一个简单的基于Web的可视化程序。 Git带有一个称为GitWeb的CGI脚本,有时用于此目的。 请按照以下步骤设置GitWeb。

a. Login to your EC2 instance

一个。 登录到您的EC2实例

-> ssh gitserver

b) Install apache2

b)安装apache2

-> sudo apt-get update-> sudo apt-get install apache2

c) Install “make” as will be required for next step

c)安装下一步需要的“ make”

-> sudo apt-get install make

d) We will get the Git source code, which GitWeb comes with, and generate the custom CGI script:

d)我们将获得GitWeb随附的Git源代码,并生成自定义CGI脚本:

-> git clone git://git.kernel.org/pub/scm/git/git.git-> cd git-> make GITWEB_PROJECTROOT=”/home/ubuntu” prefix=/usr gitweb-> sudo cp -Rf gitweb /var/www/

GITWEB_PROJECTROOT is the location of your Git repositories.

GITWEB_PROJECTROOT是您的Git存储库的位置。

e) Add VirtualHost for Apache

e)为Apache添加VirtualHost

-> cd /etc/apache2/sites-enabled/

Update conf (000-default.conf) to

将conf(000-default.conf)更新为

<VirtualHost *:80>      DocumentRoot /var/www/gitweb      <Directory /var/www/gitweb>            Options +ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch            AllowOverride All            order allow,deny            Allow from all            AddHandler cgi-script cgi            DirectoryIndex gitweb.cgi      </Directory&gt;</VirtualHost>

f) Load the mod_cgi module

f)加载mod_cgi模块

-> sudo a2enmod cgi

g) Restart apache

g)重新启动apache

-> sudo service apache2 restart

Congratulations! GitWeb is ready. Before you able to access the GitWeb on http://54.254.174.183/ (For you, it would be your instance’s public URL), there’s one last thing you need to do: allow TCP port 80 to open for your instance. You can do this by changing your security group setting for your instance.

恭喜你! GitWeb准备就绪。 在您可以通过http://54.254.174.183 /访问GitWeb之前(对于您来说,这将是您实例的公共URL),您需要做的最后一件事:允许为您的实例打开TCP端口80。 您可以通过更改实例的安全组设置来实现。

If all of this seems too complicated for you, you can go with other alternatives like GitLab. GitLab is a database-backed web application, so its installation is a bit more involved than some other git servers. Fortunately, this process is very well-documented and supported.

如果这一切对您来说都太复杂了,您可以使用其他替代方案,例如GitLab 。 GitLab是一个数据库支持的Web应用程序,因此其安装比其他一些git服务器要复杂得多。 幸运的是,此过程有充分的文档记录和支持。

If you liked the article and helped you setting up Git server, hit the heart down there and help others see it. Follow me for other such articles.

如果您喜欢这篇文章并帮助您设置了Git服务器,请打动一下并帮助其他人。 跟随我阅读其他此类文章。

翻译自: https://www.freecodecamp.org/news/create-your-own-github-kinda-9b4581db675c/

创建自己的github

创建自己的github_创建自己的GitHub(kinda)相关推荐

  1. 记录git命令:本地创建项目后如何上传到github上

    问题描述:在本地Pycharm创建了一个项目,如何将项目传到github上呢?在操作过程中遇到了一系列的问题,详情见下面: 操作过程全纪录: 1.首先登录自己的github账号,创建一个和本地的同名仓 ...

  2. Angular4.x 安装|创建项目|目录结构|创建组件

    Angular4.x 安装|创建项目|目录结构|创建组件 安装最新版本的 nodejs node.js 官网:https://nodejs.org/zh-cn/ 去官网下载 node.js,下一步下一 ...

  3. oracle创建数据库总结,oracle创建数据库和用户方法总结

    以前开发的时候用得比较多的是mysql和sql server,oracle用的比较少,用起来比较生疏,mysql和sql server用起来比较类似,就oracle的使用方式和他们不同,oracle在 ...

  4. eclipse创建springboot项目_创建一个 Spring Boot 项目,你会几种方法?

    我最早是 2016 年底开始写 Spring Boot 相关的博客,当时使用的版本还是 1.4.x ,文章发表在 CSDN 上,阅读量最大的一篇有 42W+,如下图: 2017 年由于种种原因,就没有 ...

  5. asp创建mysql表_asp创建数据库表

    一起谈.NET技术,不附加数据库 ASP.NET调用.sql文件 笔者好久没有写随笔了,这次是遇到提出这样的问题"不用附加数据库,什么修改web.config什么的那么麻烦,而是直接运行一个 ...

  6. 【设计模式】代理模式 ( 动态代理使用流程 | 创建目标对象 | 创建被代理对象 | 创建调用处理程序 | 动态创建代理对象 | 动态代理调用 )

    文章目录 前言 一.静态代理的弊端 二.动态代理的优势 三.动态代理使用流程 1.目标对象接口 2.被代理对象 3.调用处理程序 4.客户端 四.动态生成 代理对象 类 的 字节码 文件数据 前言 代 ...

  7. 【Flutter】Flutter 应用创建运行 ( Android Studio 创建 / 运行 Flutter 应用 | 命令行创建 / 运行 Flutter 应用 )

    文章目录 一.Android Studio 中创建 Flutter 应用 二. Android Studio 中运行 Flutter 应用 三. 命令行 中创建 Flutter 应用 四.命令行 中运 ...

  8. 微信门店小程序怎样创建 门店小程序创建方法简介

    微信门店小程序怎样创建 门店小程序创建方法简介 微信门店小程序是什么东西?门店小程序要怎样创建?还不清楚微信门店小程序详情的小伙伴们抓紧时间跟上小编一起来看一下吧!     门店小程序是什么? 微信发 ...

  9. 无法创建文件系统以及无法创建PV时怎么办?

    我们平常对磁盘分区格式化的时候有时无法格式化,报告的信息为: 1 "/dev/sdb3 is apparently in use by the system; will not make a ...

最新文章

  1. java debugtrace_Debug与Trace的区别
  2. 欧拉角与四元数互转,及四元数slerp球面线性插值算法
  3. 在线普通话转粤语发音_最快的学说粤语的办法:粤语拼音
  4. 虚拟字符设备驱动开发步骤
  5. dubbo启动服务启动报错.UnsatisfiedDependencyException: Error creating bean with name '***': Un
  6. python列表推导式中使用if和if-else
  7. 5不能另存为dwg_5.建立数模
  8. POJ 1661 DP
  9. HTML5 -canvas拖拽、移动 绘制图片可操作移动,拖动
  10. 从零开始搭二维激光SLAM --- Karto的后端优化与回环检测的实现解读
  11. 001_动力节点_SpringMVC4_SpringMVC简介
  12. 【资源】16个在线机器学习视频与教程
  13. 易语言MYSQL记账工具_易语言做记账软件
  14. javaFX实现登录界面并跳转
  15. SQL 注入攻击:简介与原理
  16. 推荐一些有趣的编程书籍和电影
  17. C#如何按帧截取视频,并保存为图片
  18. php 递归实现无限极分类和排序_php递归无限极分类
  19. 简单Android app之 一键签到 开发日记
  20. 苹果x重启方法_iOS 13.4.1 Linux 简易越狱,重启就能打开

热门文章

  1. 字符流的抽象类 java
  2. 熟悉HTML基本标签的分类测试分析 1218
  3. 初识类的构造方法 c# 1214
  4. 9206-1117-课堂笔记
  5. 草稿-xpath了解-python 操作xpath小例子
  6. Git相关整理以及学习
  7. 瀑布流方式三(方式二的升级版)
  8. .net framework 4.0 安装失败解决办法
  9. 网页统计所用到的名词解析
  10. UVA494 Kindergarten Counting Game