GitのリポジトリをLinuxに作成する手順

GitといえばGitHubの方が有名ですが、

GitHubは月額利用7ドル($)かかかります。

サーバ運用を丸投げできると考えると安いですが、

VPSを持っていたりや自宅サーバを持っている人はGitを自分で構築することをオススメします。

VPSについては↓の記事を参考にしてください。

投稿が見つかりません。
目次

インストール環境

今回のインストール環境は以下になります。

  • CentOS:CentOS Linux release 7.0.1406 (Core)
  • git:1.8.3.1-12.el7_4

インストール手順

今回はyumを使用してGitをインストールします。

yum install git 

↓が実行ログになります。

[root@centos7-local ~]# yum install git
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
vz-base | 951 B 00:00:00
vz-updates | 951 B 00:00:00
(1/4): base/7/x86_64/group_gz | 156 kB 00:00:01
(2/4): extras/7/x86_64/primary_db | 145 kB 00:00:01
(3/4): base/7/x86_64/primary_db | 5.7 MB 00:00:02
(4/4): updates/7/x86_64/primary_db | 5.2 MB 00:00:06
(1/2): vz-base/primary | 723 B 00:00:00
(2/2): vz-updates/primary | 758 B 00:00:00
Determining fastest mirrors
* base: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
vz-base 1/1
vz-updates 1/1
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:1.8.3.1-12.el7_4 will be installed
--> Processing Dependency: perl-Git = 1.8.3.1-12.el7_4 for package: git-1.8.3.1-12.el7_4.x86_64
--> Processing Dependency: perl(Term::ReadKey) for package: git-1.8.3.1-12.el7_4.x86_64
--> Processing Dependency: perl(Git) for package: git-1.8.3.1-12.el7_4.x86_64
--> Processing Dependency: perl(Error) for package: git-1.8.3.1-12.el7_4.x86_64
--> Processing Dependency: libgnome-keyring.so.0()(64bit) for package: git-1.8.3.1-12.el7_4.x86_64
--> Running transaction check
---> Package libgnome-keyring.x86_64 0:3.12.0-1.el7 will be installed
---> Package perl-Error.noarch 1:0.17020-2.el7 will be installed
---> Package perl-Git.noarch 0:1.8.3.1-12.el7_4 will be installed
---> Package perl-TermReadKey.x86_64 0:2.30-20.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================
Package Arch Version Repository Size
==============================================================================================================
Installing:
git x86_64 1.8.3.1-12.el7_4 updates 4.4 M
Installing for dependencies:
libgnome-keyring x86_64 3.12.0-1.el7 base 109 k
perl-Error noarch 1:0.17020-2.el7 base 32 k
perl-Git noarch 1.8.3.1-12.el7_4 updates 53 k
perl-TermReadKey x86_64 2.30-20.el7 base 31 k

Transaction Summary
==============================================================================================================
Install 1 Package (+4 Dependent packages)

Total download size: 4.6 M
Installed size: 23 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): perl-Error-0.17020-2.el7.noarch.rpm | 32 kB 00:00:00
(2/5): perl-Git-1.8.3.1-12.el7_4.noarch.rpm | 53 kB 00:00:00
(3/5): perl-TermReadKey-2.30-20.el7.x86_64.rpm | 31 kB 00:00:00
(4/5): libgnome-keyring-3.12.0-1.el7.x86_64.rpm | 109 kB 00:00:00
(5/5): git-1.8.3.1-12.el7_4.x86_64.rpm | 4.4 MB 00:00:01
--------------------------------------------------------------------------------------------------------------
Total 2.5 MB/s | 4.6 MB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:perl-Error-0.17020-2.el7.noarch 1/5
Installing : perl-TermReadKey-2.30-20.el7.x86_64 2/5
Installing : libgnome-keyring-3.12.0-1.el7.x86_64 3/5
Installing : perl-Git-1.8.3.1-12.el7_4.noarch 4/5
Installing : git-1.8.3.1-12.el7_4.x86_64 5/5
Verifying : git-1.8.3.1-12.el7_4.x86_64 1/5
Verifying : 1:perl-Error-0.17020-2.el7.noarch 2/5
Verifying : libgnome-keyring-3.12.0-1.el7.x86_64 3/5
Verifying : perl-Git-1.8.3.1-12.el7_4.noarch 4/5
Verifying : perl-TermReadKey-2.30-20.el7.x86_64 5/5

Installed:
git.x86_64 0:1.8.3.1-12.el7_4

Dependency Installed:
libgnome-keyring.x86_64 0:3.12.0-1.el7 perl-Error.noarch 1:0.17020-2.el7 perl-Git.noarch 0:1.8.3.1-12.el7_4
perl-TermReadKey.x86_64 0:2.30-20.el7

Complete!
[root@centos7-local ~]#

Last login: Mon Jan 15 01:07:14 2018 from kd106154084058.au-net.ne.jp

実はGitのインストールの作成は終了です。

リポジトリの作成

ここからはリポジトリの作成を行います。

  1. Git用ユーザーの作成
  2. Gitリポジトリの作成

Git用ユーザーの作成

Git用のグループとユーザを作成します。

groupadd <Git用グループ>
useradd -g gitgroup <Git用ユーザ>

↓が実行ログになります。

[root@centos7-local ~]# groupadd gitgroup
[root@centos7-local ~]# useradd -g gitgroup gituser
[root@centos7-local ~]# passwd gituser
Changing password for user gituser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@centos7-local ~]# id gituser
uid=1000(gituser) gid=1000(gitgroup) groups=1000(gitgroup)
[root@centos7-local ~]#

Gitリポジトリの作成

リポジトリ用のディレクトリを作成しリポジトリを作成します。

mkdir -p <Git用ディレクトリパス>
chown <Git用ユーザ>:<Git用グループ> <Git用ディレクトリパス>

作成したGitユーザで下のコマンドを実行します。

git init --bare --shared 

↓が実行ログになります。

[root@centos7-local ~]# mkdir -p /app/git/rep.git
[root@centos7-local ~]# cd /app/git/
[root@centos7-local git]# chown gituser:gitgroup rep.git
[root@centos7-local git]#
[root@centos7-local git]#
[root@centos7-local git]#
[root@centos7-local git]#
[root@centos7-local git]# ls -l
total 4
drwxr-xr-x 2 gituser gitgroup 4096 Jan 15 09:59 rep.git
[root@centos7-local git]# su - gituser
[gituser@centos7-local ~]$ cd /app/git/
[gituser@centos7-local git]$ cd /app/git/rep.git/
[gituser@centos7-local rep.git]$
[gituser@centos7-local rep.git]$ pwd
/app/git/rep.git
[gituser@centos7-local rep.git]$
[gituser@centos7-local rep.git]$ git init --bare --shared
Initialized empty shared Git repository in /app/git/rep.git/
[gituser@centos7-local rep.git]$ ls -la
total 40
drwxrwsr-x 7 gituser gitgroup 4096 Jan 15 10:09 .
drwxr-xr-x 3 root root 4096 Jan 15 09:59 ..
-rw-rw-r-- 1 gituser gitgroup 23 Jan 15 10:09 HEAD
drwxrwsr-x 2 gituser gitgroup 4096 Jan 15 10:09 branches
-rw-rw-r-- 1 gituser gitgroup 126 Jan 15 10:09 config
-rw-rw-r-- 1 gituser gitgroup 73 Jan 15 10:09 description
drwxrwsr-x 2 gituser gitgroup 4096 Jan 15 10:09 hooks
drwxrwsr-x 2 gituser gitgroup 4096 Jan 15 10:09 info
drwxrwsr-x 4 gituser gitgroup 4096 Jan 15 10:09 objects
drwxrwsr-x 4 gituser gitgroup 4096 Jan 15 10:09 refs
[gituser@centos7-local rep.git]$

.git」というディレクトリはGit界隈ではスタンダードな命名規則のようです。

確認作業:リポジトリのクローンを作成してみる

クローンの作成方法は以下になります。

git clone ssh://<Gitユーザ名>@<ホスト名>:<SSHポート番号><Gitリポジトリの絶対パス> <プロジェクト名>

↓が実行ログです。

リポジトリに何も登録していないのでwarningが発生しています。

[gituser@centos7-local ~]$ git clone ssh://gituser@localhost:2222/app/git/rep.git testproject
Cloning into 'testproject'...
gituser@localhost's password:
warning: You appear to have cloned an empty repository.
[gituser@centos7-local ~]$

以上で終了です。↓の本で勉強中です。

よかったら目を通してみてください。

わかばちゃんと学ぶGit使い方入門posted with ヨメレバ

湊川あい/DQNEO シーアンドアール研究所 2017年04月22日

Amazon

Kindle

楽天ブックス

7net

honto

e-hon

紀伊國屋書店

独習Gitposted with ヨメレバ

リック・ウマリ/吉川邦夫 翔泳社 2016年02月15日

Amazon

Kindle

楽天ブックス

7net

honto

e-hon

紀伊國屋書店

よかったらシェアしてね!
  • URLをコピーしました!
目次