Git : インストール2023/07/25 |
バージョン管理システム Git のインストールと設定です。
|
|
[1] | Git をインストールします。 |
root@dlp:~# apt -y install git
|
[2] | 任意の一般ユーザーで利用可能です。 例として、任意の一般ユーザーが GitHub 等のリモートリポジトリを利用せず、ローカルホスト上に自身が使用するリポジトリを作成して利用します。 |
# 空リポジトリ作成 debian@dlp:~$ mkdir project.git debian@dlp:~$ cd project.git debian@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/debian/project.git/
debian@dlp:~/project.git$
# 作業用ディレクトリ作成 debian@dlp:~$ mkdir work debian@dlp:~$ cd work debian@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/debian/work/.git/ # ユーザー名とメールアドレスの設定 debian@dlp:~/work$ git config --global user.name "Server World" debian@dlp:~/work$ git config --global user.email "serverworld@dlp.srv.world"
# テストファイルを作成してリポジトリに反映 debian@dlp:~/work$ echo testfile > testfile1.txt debian@dlp:~/work$ git add testfile1.txt debian@dlp:~/work$ git commit testfile1.txt -m "Initial Commit" [master (root-commit) 5e4fdad] Initial Commit 1 file changed, 1 insertion(+) create mode 100644 testfile1.txtdebian@dlp:~/work$ git push /home/debian/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 To /home/debian/project.git * [new branch] master -> masterdebian@dlp:~/work$ git ls-files testfile1.txt # リポジトリに任意の名称を登録 debian@dlp:~/work$ git remote add origin /home/debian/project.git debian@dlp:~/work$ git remote -v origin /home/debian/project.git (fetch) origin /home/debian/project.git (push)debian@dlp:~/work$ git remote show origin * remote origin Fetch URL: /home/debian/project.git Push URL: /home/debian/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 可 debian@dlp:~/work$ echo testfile > testfile2.txt debian@dlp:~/work$ git add testfile2.txt debian@dlp:~/work$ git commit testfile2.txt -m "New Commit testfile2.txt" [master f6dfd1e] New Commit testfile2.txt 1 file changed, 1 insertion(+) create mode 100644 testfile2.txtdebian@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), 258 bytes | 258.00 KiB/s, done. Total 2 (delta 0), reused 0 (delta 0), pack-reused 0 To /home/debian/project.git 5e4fdad..f6dfd1e master -> master # 既存のリポジトリから空の作業ディレクトリにデータを複製する場合は以下 debian@dlp:~/work$ mkdir ~/work2 debian@dlp:~/work$ cd ~/work2 debian@dlp:~/work2$ git clone /home/debian/project.git Cloning into 'project'... done.debian@dlp:~/work2$ total 4 drwxr-xr-x 3 debian debian 4096 Jul 24 19:07 projectdebian@dlp:~/work2$ ll project total 8 -rw-r--r-- 1 debian debian 9 Jul 24 19:07 testfile1.txt -rw-r--r-- 1 debian debian 9 Jul 24 19:07 testfile2.txt |
Sponsored Link |