LoginSignup
1
0

More than 5 years have passed since last update.

自鯖へgitをインストールして、CUIでそのまま使う

Posted at

Git を自鯖で使おうと

git でバージョン管理は便利であり、WEBでもbitbucketや、git lab Git hubなど様々なサービスが展開されており、

誰でも、簡単にソースコードをプライベートでもパブリックでもバージョン管理できます。

素敵です。

そんなgitを自鯖にて運用してみました。

私のgit のバージョン、yumでいれると1.7かもしれませんが多分大丈夫。

keisukeYamagishi:~$ git --version
git version 2.2.0

詳しくは、下記参照
https://git-scm.com/book/ja/v1/%E4%BD%BF%E3%81%84%E5%A7%8B%E3%82%81%E3%82%8B-Git%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB

まずはサーバー側、

keisukeYamagishi:~$ cd /
keisukeYamagishi::$ sudo mkdir git
[sudo] password for keisukeYamagishi: 
keisukeYamagishi:~$ cd /git/
keisukeYamagishi:/git$ ls -a
.  ..
keisukeYamagishi:/git$ sudo mkdir Repo.git
[sudo] password for keisukeYamagishi: 
keisukeYamagishi:/git$ ls -l
合計 4
drwxr-sr-x 2 root root 4096  7月  2 12:34 2017 Repo.git
keisukeYamagishi:/git$ sudo chmod g+ws Repo.git/
keisukeYamagishi:/git$ ls -ll
合計 4
drwxrwsr-x 2 root root 4096  7月  2 12:34 2017 Repo.git
keisukeYamagishi:/git$ sudo chown root:git Repo.git/
keisukeYamagishi:/git$ ls -ll
合計 4
drwxrwsr-x 2 root git 4096  7月  2 12:34 2017 Repo.git
keisukeYamagishi:/git$ cd Repo.git/
keisukeYamagishi:/git/Repo.git$ ls -a
.  ..
keisukeYamagishi:/git/Repo.git$ sudo git --bare init --shared
Initialized empty shared Git repository in /git/Repo.git/
keisukeYamagishi:/git/Repo.git$ ls -a
.  ..  HEAD  branches  config  description  hooks  info  objects  refs
keisukeYamagishi:/git/Repo.git$ ls -ll
合計 32
-rw-rw-r-- 1 root git   23  7月  2 12:36 2017 HEAD
drwxrwsr-x 2 root git 4096  7月  2 12:36 2017 branches
-rwxrw-r-- 1 root git  126  7月  2 12:36 2017 config
-rw-rw-r-- 1 root git   73  7月  2 12:36 2017 description
drwxrwsr-x 2 root git 4096  7月  2 12:36 2017 hooks
drwxrwsr-x 2 root git 4096  7月  2 12:36 2017 info
drwxrwsr-x 4 root git 4096  7月  2 12:36 2017 objects
drwxrwsr-x 4 root git 4096  7月  2 12:36 2017 refs
keisukeYamagishi:/git/Repo.git$ sudo chmod g+ws *
keisukeYamagishi:/git/Repo.git$ ls -l
合計 32
-rw-rwSr-- 1 root git   23  7月  2 12:36 2017 HEAD
drwxrwsr-x 2 root git 4096  7月  2 12:36 2017 branches
-rwxrwSr-- 1 root git  126  7月  2 12:36 2017 config
-rw-rwSr-- 1 root git   73  7月  2 12:36 2017 description
drwxrwsr-x 2 root git 4096  7月  2 12:36 2017 hooks
drwxrwsr-x 2 root git 4096  7月  2 12:36 2017 info
drwxrwsr-x 4 root git 4096  7月  2 12:36 2017 objects
drwxrwsr-x 4 root git 4096  7月  2 12:36 2017 refs
keisukeYamagishi:/git/Repo.git$ pwd
/git/Repo.git

sshでログインした後から権限から、レポジトリー作成まで、

ここから、ローカル側、実際にgit init してから自鯖にコミットしてます。


keisukeYamagishi_local:~: $ cd Documents/
keisukeYamagishi_local:~/Documents: $ mkdir Repo
keisukeYamagishi_local:~/Documents: $ cd Repo/
keisukeYamagishi_local:~/Documents/Repo: $ ls -a
.   ..
keisukeYamagishi_local:~/Documents/Repo: $ git init
Initialized empty Git repository in /Users/keisukeYamagishi_local/Documents/Repo/.git/
keisukeYamagishi_local:~/Documents/Repo: $ ls -a
.   ..  .git
keisukeYamagishi_local:~/Documents/Repo: $ git remote add origin ssh://git@160.16.86.88/git/Repo.git
keisukeYamagishi_local:~/Documents/Repo: $ ls -a
.   ..  .git
keisukeYamagishi_local:~/Documents/Repo: $ vi README.md
keisukeYamagishi_local:~/Documents/Repo: $ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    README.md

nothing added to commit but untracked files present (use "git add" to track)
keisukeYamagishi_local:~/Documents/Repo: $ git add -A
keisukeYamagishi_local:~/Documents/Repo: $ git commit -m "add README.md"
[master (root-commit) 2b77593] add README.md
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
keisukeYamagishi_local:~/Documents/Repo: $ git push -u origin master
Password:  
Counting objects: 3, done.
Writing objects: 100% (3/3), 229 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://160.16.86.88/git/Repo.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
keisukeYamagishi_local:~/Documents/Repo: $ ls -a
.       ..      .git        README.md
keisukeYamagishi_local:~/Documents/Repo: $ git remote -v
origin  ssh://git@160.16.86.88/git/Repo.git (fetch)
origin  ssh://git@160.16.86.88/git/Repo.git (push)
keisukeYamagishi_local:~/Documents/Repo: $ ..

keisukeYamagishi_local:~/Documents/git: $ git clone ssh://git@160.16.86.88/git/Repo.git
Cloning into 'Repo'...
Password: 
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
keisukeYamagishi_local:~/Documents/git: $ ls -a
.       ..      Repo

自鯖gitでした。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0