Git : インストール2020/04/14 |
バージョン管理システム Git のインストールと設定です。
|
|
[1] | Git をインストールします。 |
[root@dlp ~]# dnf -y install git
|
[2] | 任意の一般ユーザーで利用可能です。 例として、任意の一般ユーザーが GitHub 等のリモートリポジトリを利用せず、ローカルホスト上に自身が使用するリポジトリを作成して利用します。 |
# 空リポジトリ作成 [cent@dlp ~]$ mkdir project.git [cent@dlp ~]$ cd project.git [cent@dlp project.git]$ git init --bare Initialized empty Git repository in /home/cent/project.git/
[cent@dlp ~]$
# 作業用ディレクトリ作成 [cent@dlp ~]$ mkdir work [cent@dlp ~]$ cd work [cent@dlp work]$ git init Initialized empty Git repository in /home/cent/work/.git/ # ユーザー名とメールアドレスの設定 [cent@dlp work]$ git config --global user.name "Server World" [cent@dlp work]$ git config --global user.email "cent@dlp.srv.world"
# テストファイルを作成してリポジトリに反映 [cent@dlp work]$ echo testfile > testfile1.txt [cent@dlp work]$ git add testfile1.txt [cent@dlp work]$ git commit testfile1.txt -m "Initial Commit" [master (root-commit) cd237aa] Initial Commit 1 file changed, 1 insertion(+) create mode 100644 testfile1.txt[cent@dlp work]$ git push /home/cent/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) To /home/cent/project.git * [new branch] master -> master[cent@dlp work]$ git ls-files testfile1.txt # リポジトリに任意の名称を登録 [cent@dlp work]$ git remote add origin /home/cent/project.git [cent@dlp work]$ git remote -v origin /home/cent/project.git (fetch) origin /home/cent/project.git (push)[cent@dlp work]$ git remote show origin * remote origin Fetch URL: /home/cent/project.git Push URL: /home/cent/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 可 [cent@dlp work]$ echo testfile > testfile2.txt [cent@dlp work]$ git add testfile2.txt [cent@dlp work]$ git commit testfile2.txt -m "New Commit testfile2.txt" [master 470377f] New Commit testfile2.txt 1 file changed, 1 insertion(+) create mode 100644 testfile2.txt[cent@dlp work]$ git push origin master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Delta compression using up to 4 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) To /home/cent/project.git cd237aa..470377f master -> master # 既存のリポジトリから空の作業ディレクトリにデータを複製する場合は以下 [cent@dlp work]$ mkdir ~/work2 [cent@dlp work]$ cd ~/work2 [cent@dlp work2]$ git clone /home/cent/project.git Cloning into 'project'... done.[cent@dlp work2]$ total 0 drwxrwxr-x. 3 cent cent 60 Apr 09 19:30 project[cent@dlp work2]$ ll project total 8 -rw-rw-r--. 1 cent cent 9 Apr 09 19:30 testfile1.txt -rw-rw-r--. 1 cent cent 9 Apr 09 19:30 testfile2.txt |
Sponsored Link |
|