FreeBSD 14
Sponsored Link

Git : インストール2024/09/13

 

バージョン管理システム Git のインストールと設定です。

[1] Git をインストールします。
root@dlp:~ #
pkg install -y git
[2] 任意の一般ユーザーで利用可能です。
例として、任意の一般ユーザーが GitHub 等のリモートリポジトリを利用せず、ローカルホスト上に自身が使用するリポジトリを作成して利用します。
# 空リポジトリ作成

freebsd@dlp:~ $
mkdir project.git

freebsd@dlp:~ $
cd project.git

freebsd@dlp:~/project.git $
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 Git repository in /home/freebsd/project.git/

freebsd@dlp:~/project.git $
cd
# 作業用ディレクトリ作成

freebsd@dlp:~ $
mkdir work

freebsd@dlp:~ $
cd work

freebsd@dlp:~/work $
git init

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 Git repository in /home/freebsd/work/.git/

# ユーザー名とメールアドレスの設定

freebsd@dlp:~/work $
git config --global user.name "Server World"

freebsd@dlp:~/work $
git config --global user.email "serverworld@dlp.srv.world"
# テストファイルを作成してリポジトリに反映

freebsd@dlp:~/work $
echo testfile > testfile1.txt

freebsd@dlp:~/work $
git add testfile1.txt

freebsd@dlp:~/work $
git commit testfile1.txt -m "Initial Commit"

[master (root-commit) ae100aa] Initial Commit
 1 file changed, 1 insertion(+)
 create mode 100644 testfile1.txt

freebsd@dlp:~/work $
git push /home/freebsd/project.git master

Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 231 bytes | 231.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To /home/freebsd/project.git
 * [new branch]      master -> master

freebsd@dlp:~/work $
git ls-files

testfile1.txt

# リポジトリに任意の名称を登録

freebsd@dlp:~/work $
git remote add origin /home/freebsd/project.git

freebsd@dlp:~/work $
git remote -v

origin  /home/freebsd/project.git (fetch)
origin  /home/freebsd/project.git (push)

freebsd@dlp:~/work $
git remote show origin

* remote origin
  Fetch URL: /home/freebsd/project.git
  Push  URL: /home/freebsd/project.git
  HEAD branch: master
  Remote branch:
    master new (next fetch will store in remotes/origin)
  Local ref configured for 'git push':
    master pushes to master (up to date)

# リポジトリに登録した名称で push 可

freebsd@dlp:~/work $
echo testfile > testfile2.txt

freebsd@dlp:~/work $
git add testfile2.txt

freebsd@dlp:~/work $
git commit testfile2.txt -m "New Commit testfile2.txt"

[master a1e474d] New Commit testfile2.txt
 1 file changed, 1 insertion(+)
 create mode 100644 testfile2.txt

freebsd@dlp:~/work $
git push origin master

Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 256 bytes | 256.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To /home/freebsd/project.git
   ae100aa..a1e474d  master -> master

# 既存のリポジトリから空の作業ディレクトリにデータを複製する場合は以下

freebsd@dlp:~/work $
mkdir ~/work2

freebsd@dlp:~/work $
cd ~/work2

freebsd@dlp:~/work2 $
git clone /home/freebsd/project.git

Cloning into 'project'...
done.

freebsd@dlp:~/work2 $
ls -l

total 1
drwxr-xr-x  3 freebsd freebsd 5 Sep 13 11:20 project

freebsd@dlp:~/work2 $
ls -la project

total 11
drwxr-xr-x  3 freebsd freebsd  5 Sep 13 11:20 .
drwxr-xr-x  3 freebsd freebsd  3 Sep 13 11:20 ..
drwxr-xr-x  8 freebsd freebsd 13 Sep 13 11:20 .git
-rw-r--r--  1 freebsd freebsd  9 Sep 13 11:20 testfile1.txt
-rw-r--r--  1 freebsd freebsd  9 Sep 13 11:20 testfile2.txt
関連コンテンツ