LoginSignup
2
0

More than 1 year has passed since last update.

バージョン管理 - Gitのインストール

Posted at

はじめに

今回はGitを使い始める前にコンピュータ(利用OS)でそれを使えるようにします。
バイナリのインストーラーを用いてLinux上へGitと主な関連ツールをインストールしていきましょう。
なお、インストールはMacOS、LinuxOSによって方法がいくつかあります。
今回は、LinuxOSに対し簡易的に導入できる方法をご紹介します。

Gitのインストール

yumを用いてインストールしていきます。

$ yum install git-all

※接続ユーザにてインストール権限がない場合、sudo にて権限を与えつつ実行する。

初期設定

Git をインストールしたら、名前とメールアドレスをグローバルの設定ファイルに設定します。

$ git config --global user.name "[任意の名前]"
$ git config --global user.email "[任意のメールアドレス]"

上記設定を行うことで、 ~/.gitconfig ファイルが次のように設定されます。

[user]
    name = [任意の名前]
    email = [任意のメールアドレス]

あとで変更も可能です。
変更は git config コマンドを利用して設定してもよいですし、~/.gitconfig を直接編集しても構いません。

プロジェクトごとにユーザを設定する場合は、作成したリポジトリフォルダごとに別途設定します。

1度設定している情報の確認は以下でできます。

$ git config --list

リポジトリの作成

①任意の場所にGit用のフォルダを作成します。
 どこに作成してもよいのですが、今回は「/var/lib/git」に作成します。

$ cd /var/lib/git/
$ sudo mkdir [任意のフォルダ名]
$ cd [任意のフォルダ名]

②管理専用でリポジトリを作成します。

$ git init --bare

 実行すると、下記のようにメッセージが出力されリポジトリが作成されます。

hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint:   git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint:   git branch -m <name>
Initialized empty shared Git repository in /var/lib/git/[任意のフォルダ名]/

③フォルダを確認すると、Gitのプロジェクト用フォルダが作成されています。

$ ls -al
total 16
drwxrwsr-x 7 ec2-user ec2-user  119 Nov 30 15:01 .
drwxr-xr-x 3 root     root       22 Nov 30 15:00 ..
drwxrwsr-x 2 ec2-user ec2-user    6 Nov 30 15:01 branches
-rw-rw-r-- 1 ec2-user ec2-user  126 Nov 30 15:01 config
-rw-rw-r-- 1 ec2-user ec2-user   73 Nov 30 15:01 description
-rw-rw-r-- 1 ec2-user ec2-user   23 Nov 30 15:01 HEAD
drwxrwsr-x 2 ec2-user ec2-user 4096 Nov 30 15:01 hooks
drwxrwsr-x 2 ec2-user ec2-user   21 Nov 30 15:01 info
drwxrwsr-x 4 ec2-user ec2-user   30 Nov 30 15:01 objects
drwxrwsr-x 4 ec2-user ec2-user   31 Nov 30 15:01 refs

 おわりに

本日はここまでとなります。
開発時にブランチを切って開発を進めていくことでブランチごとにバージョン管理が利用できると思います。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0