Git : インストール2025/12/24 |
|
バージョン管理システム Git のインストールと設定です。 |
|
| [1] | Git をインストールします。 |
|
dlp:~ # zypper -n install git
|
| [2] | 任意の一般ユーザーで利用可能です。 例として、任意の一般ユーザーが GitHub 等のリモートリポジトリを利用せず、ローカルホスト上に自身が使用するリポジトリを作成して利用します。 |
|
# 空リポジトリ作成 suse@dlp:~> mkdir project.git suse@dlp:~> cd project.git suse@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> hint: hint: Disable this message with "git config set advice.defaultBranchName false" Initialized empty Git repository in /home/suse/project.git/
suse@dlp:~/project.git>
# 作業用ディレクトリ作成 suse@dlp:~> mkdir work suse@dlp:~> cd work suse@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> hint: hint: Disable this message with "git config set advice.defaultBranchName false" Initialized empty Git repository in /home/suse/work/.git/ # ユーザー名とメールアドレスの設定 suse@dlp:~/work> git config --global user.name "Server World" suse@dlp:~/work> git config --global user.email "serverworld@dlp.srv.world"
# テストファイルを作成してリポジトリに反映 suse@dlp:~/work> echo testfile > testfile1.txt suse@dlp:~/work> git add testfile1.txt suse@dlp:~/work> git commit testfile1.txt -m "Initial Commit" [master (root-commit) 7ce70a0] Initial Commit 1 file changed, 1 insertion(+) create mode 100644 testfile1.txtsuse@dlp:~/work> git push $HOME/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/suse/project.git * [new branch] master -> mastersuse@dlp:~/work> git ls-files testfile1.txt # リポジトリに任意の名称を登録 suse@dlp:~/work> git remote add origin $HOME/project.git suse@dlp:~/work> git remote -v origin /home/suse/project.git (fetch) origin /home/suse/project.git (push)suse@dlp:~/work> git remote show origin
* remote origin
Fetch URL: /home/suse/project.git
Push URL: /home/suse/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 可 suse@dlp:~/work> echo testfile > testfile2.txt suse@dlp:~/work> git add testfile2.txt suse@dlp:~/work> git commit testfile2.txt -m "New Commit testfile2.txt" [master b81fa39] New Commit testfile2.txt 1 file changed, 1 insertion(+) create mode 100644 testfile2.txtsuse@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 (from 0) To /home/suse/project.git 7ce70a0..b81fa39 master -> master # 既存のリポジトリから空の作業ディレクトリにデータを複製する場合は以下 suse@dlp:~/work> mkdir ~/work2 suse@dlp:~/work> cd ~/work2 suse@dlp:~/work2> git clone $HOME/project.git Cloning into 'project'... done.suse@dlp:~/work2> total 0 drwxr-xr-x. 1 suse suse 34 Dec 24 08:43 projectsuse@dlp:~/work2> ll project total 8 -rw-r--r--. 1 suse suse 9 Dec 24 08:45 testfile1.txt -rw-r--r--. 1 suse suse 9 Dec 24 08:45 testfile2.txt |
| Sponsored Link |
|
|