Ubuntu 22.04
Sponsored Link

Git : インストール2022/09/27

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

ubuntu@dlp:~$
mkdir project.git

ubuntu@dlp:~$
cd project.git

ubuntu@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/ubuntu/project.git/

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

ubuntu@dlp:~$
mkdir work

ubuntu@dlp:~$
cd work

ubuntu@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/ubuntu/work/.git/

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

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

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

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

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

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

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

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

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

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

testfile1.txt

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

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

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

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

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

* remote origin
  Fetch URL: /home/ubuntu/project.git
  Push  URL: /home/ubuntu/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 可

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

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

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

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

ubuntu@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
To /home/ubuntu/project.git
   ffab540..6de7da8  master -> master

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

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

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

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

Cloning into 'project'...
done.

ubuntu@dlp:~/work2$
total 12
drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 23 05:22 ./
drwxr-x--- 7 ubuntu ubuntu 4096 Sep 23 05:22 ../
drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 23 05:22 project/
ubuntu@dlp:~/work2$
ll project

total 20
drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 23 05:22 ./
drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 23 05:22 ../
drwxrwxr-x 8 ubuntu ubuntu 4096 Sep 23 05:22 .git/
-rw-rw-r-- 1 ubuntu ubuntu    9 Sep 23 05:22 testfile1.txt
-rw-rw-r-- 1 ubuntu ubuntu    9 Sep 23 05:22 testfile2.txt
関連コンテンツ